diff --git a/build/main/core/Account.d.ts b/build/main/core/Account.d.ts index 322060c..a37c64a 100644 --- a/build/main/core/Account.d.ts +++ b/build/main/core/Account.d.ts @@ -2,17 +2,17 @@ import QOSRpc from './QOSRpc'; import { IApproveInput } from './Txs/Approve'; import { ITransferInput } from './Txs/Bank'; import { ICreateDelegationInput, IModifyDelegationInput, IUnbondDelegationInput } from './Txs/Delegation'; -import { IKeyPair } from './types/common'; +import { IAcc, IKeyPair } from './types/common'; declare class Account { readonly rpc: QOSRpc; qos: number; mnemonic: string; keypair: IKeyPair; address: string; - pubKey: string; privateKey: string; - bech32pubkey: string; - constructor(controller: QOSRpc, keyPair?: IKeyPair, mnemonic?: string); + privateKeyBz: Uint8Array; + pubKeyBz: Uint8Array; + constructor(controller: QOSRpc, Acc?: IAcc, mnemonic?: string); sendTransferTx(toAddress: string, data: ITransferInput): Promise>; sendCreateDelegateTx(validatorAddress: string, data: ICreateDelegationInput): Promise>; sendModifyDelegationTx(validatorAddress: string, data: IModifyDelegationInput): Promise>; @@ -25,6 +25,7 @@ declare class Account { sendUseApproveTx(toAddress: string, data: IApproveInput): Promise>; queryDelagationAll(deleagtorAddress: string): Promise>; queryDelagationOne(deleagtorAddress: string, validatorAddress: string): Promise>; + queryValidatorAll(): Promise>; queryValidatorOne(validatorAddress: string): Promise>; queryAccount(accountAddress: any): Promise>; } diff --git a/build/main/core/Account.js b/build/main/core/Account.js index c2660fe..4ac4731 100644 --- a/build/main/core/Account.js +++ b/build/main/core/Account.js @@ -6,27 +6,25 @@ Object.defineProperty(exports, "__esModule", { value: true }); const Approve_1 = __importDefault(require("./Txs/Approve")); const Bank_1 = __importDefault(require("./Txs/Bank")); const Delegation_1 = __importDefault(require("./Txs/Delegation")); -const utils_1 = require("./utils"); -const log_1 = __importDefault(require("./utils/log")); // import { ITransferInput } from './' class Account { - constructor(controller, keyPair, mnemonic) { + constructor(controller, Acc, mnemonic) { // public account: IAccount this.qos = 0; this.rpc = controller; - if (keyPair) { + if (Acc) { this.mnemonic = mnemonic; - this.keypair = keyPair; - this.address = this.rpc.key.getAddress(keyPair.publicKey); - this.pubKey = utils_1.encodeBase64(keyPair.publicKey); - this.privateKey = utils_1.encodeBase64(keyPair.privateKey); - this.bech32pubkey = keyPair.bech32pubkey; + this.keypair = Acc.keyPair; + this.privateKey = Acc.keyPair.hexPrivateKey; + // this.pubKey = Acc.keyPair.pubKey; + this.address = Acc.address; + this.privateKeyBz = Acc.keyPair.privateKey; + this.pubKeyBz = Acc.keyPair.pubKey; } } async sendTransferTx(toAddress, data) { const tx = new Bank_1.default(this.rpc, this); const res = await tx.execTransferTx(toAddress, data); - log_1.default.debug('transfer result', res); return res; } async sendCreateDelegateTx(validatorAddress, data) { @@ -84,6 +82,11 @@ class Account { const res = await tx.execQueryDelegationOne(deleagtorAddress, validatorAddress); return res; } + async queryValidatorAll() { + const tx = new Delegation_1.default(this.rpc, this); + const res = await tx.execQueryValidatorAll(); + return res; + } async queryValidatorOne(validatorAddress) { const tx = new Delegation_1.default(this.rpc, this); const res = await tx.execQueryValidatorOne(validatorAddress); @@ -96,4 +99,4 @@ class Account { } } exports.default = Account; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQWNjb3VudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9jb3JlL0FjY291bnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFDQSw0REFBdUQ7QUFDdkQsc0RBQWtEO0FBQ2xELGtFQUFzSDtBQUV0SCxtQ0FBdUM7QUFDdkMsc0RBQWlDO0FBQ2pDLHNDQUFzQztBQUV0QyxNQUFNLE9BQU87SUFXWCxZQUFZLFVBQWtCLEVBQUUsT0FBa0IsRUFBRSxRQUFpQjtRQVRyRSwyQkFBMkI7UUFDcEIsUUFBRyxHQUFXLENBQUMsQ0FBQztRQVNyQixJQUFJLENBQUMsR0FBRyxHQUFHLFVB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xNQUFNLEdBQUcsR0FBRyxNQUFNLEVBQUUsQ0FBQyxxQkFBcUIsQ0FBQyxnQkFBZ0IsQ0FBQyxDQUFBO1FBQzVELE9BQU8sR0FBRyxDQUFBO0lBQ1osQ0FBQztJQUVNLEtBQUssQ0FBQyxZQUFZLENBQUMsY0FBYztRQUN0QyxNQUFNLEVBQUUsR0FBRyxJQUFJLGNBQUksQ0FBQyxJQUFJLENBQUMsR0FBRyxFQUFFLElBQUksQ0FBQyxDQUFDO1FBQ3BDLE1BQU0sR0FBRyxHQUFHLE1BQU0sRUFBRSxDQUFDLGdCQUFnQixDQUFDLGNBQWMsQ0FBQyxDQUFBO1FBQ3JELE9BQU8sR0FBRyxDQUFDO0lBQ2IsQ0FBQztDQUdGO0FBRUQsa0JBQWUsT0FBTyxDQUFDIn0= \ No newline at end of file diff --git a/build/main/core/QOSRpc.d.ts b/build/main/core/QOSRpc.d.ts index 57ab5ea..c4a338f 100644 --- a/build/main/core/QOSRpc.d.ts +++ b/build/main/core/QOSRpc.d.ts @@ -21,6 +21,7 @@ export declare class QOSRpc { * 根据私钥恢复账户 * @param {string} privateKey 私钥 */ - recoveryAccountByPrivateKey(privateKey: any): Account; + recoveryAccountByPrivateKey(privateKey: string): Account; + verifyBech32StringByAccAddress(accAddress: string): any; } export default QOSRpc; diff --git a/build/main/core/QOSRpc.js b/build/main/core/QOSRpc.js index 592ecb5..bd7a8a0 100644 --- a/build/main/core/QOSRpc.js +++ b/build/main/core/QOSRpc.js @@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); const Account_1 = __importDefault(require("./Account")); const SecretKey_1 = __importDefault(require("./SecretKey")); const Tx_1 = __importDefault(require("./Tx")); -const utils_1 = require("./utils"); const request_1 = __importDefault(require("./utils/request")); class QOSRpc { constructor(config) { @@ -40,12 +39,15 @@ class QOSRpc { * @param {string} privateKey 私钥 */ recoveryAccountByPrivateKey(privateKey) { - const privateKeyBuffer = utils_1.decodeBase64(privateKey); - // const keyPair = nacl.sign.keyPair.fromSecretKey(privateKeyBuffer); - const keyPair = this.key.recoveryKeyPair(privateKeyBuffer); + const keyPair = this.key.recoveryKeyPair(privateKey); return new Account_1.default(this, keyPair); } + // 账户地址格式校验 + verifyBech32StringByAccAddress(accAddress) { + const isValidate = this.key.verifyBech32String(accAddress); + return isValidate; + } } exports.QOSRpc = QOSRpc; exports.default = QOSRpc; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUU9TUnBjLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2NvcmUvUU9TUnBjLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUEsd0RBQWdDO0FBQ2hDLDREQUFvQztBQUNwQyw4Q0FBc0I7QUFFdEIsbUNBQXVDO0FBQ3ZDLDhEQUFnRDtBQUVoRCxNQUFhLE1BQU07SUFnQmpCLFlBQVksTUFBcUM7UUFDL0MsSUFBSSxDQUFDLE1BQU0sR0FBRyxNQUFNLENBQUM7UUFDckIsSUFBSSxDQUFDLEdBQUcsR0FBRyxJQUFJLG1CQUFTLEVBQUUsQ0FBQztJQUM3QixDQUFDO0lBakJELElBQVcsT0FBTztRQUNoQixPQUFPLGlCQUFpQixDQUFDLElBQUksQ0FBQyxNQUFNLENBQUMsT0FBTyxDQUFDLENBQUM7SUFDaEQsQ0FBQztJQUVELElBQVcsRUFBRTtRQUNYLElBQUksQ0FBQyxJQUFJLENBQUMsR0FBRyxFQUFFO1lBQ2IsSUFBSSxDQUFDLEdBQUcsR0FBRyxJQUFJLFlBQUUsQ0FBQyxJQUFJLENBQUMsQ0FBQTtTQUN4QjtRQUNELE9BQU8sSUFBSSxDQUFDLEdBQUcsQ0FBQTtJQUNqQixDQUFDO0lBU00sSUFBSSxDQUFDLEdBQVUsRUFBRSxJQUFlO1FBQ3JDLE9BQU8sSUFBSSxDQUFDLE9BQU8sQ0FBQyxJQUFJLEN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BRSxPQUFPLEVBQUUsUUFBUSxDQUFDLENBQUM7SUFDOUMsQ0FBQztJQUVEOzs7T0FHRztJQUNJLDJCQUEyQixDQUFDLFVBQWtCO1FBQ25ELE1BQU0sT0FBTyxHQUFHLElBQUksQ0FBQyxHQUFHLENBQUMsZUFBZSxDQUFDLFVBQVUsQ0FBQyxDQUFBO1FBQ3BELE9BQU8sSUFBSSxpQkFBTyxDQUFDLElBQUksRUFBRSxPQUFPLENBQUMsQ0FBQztJQUNwQyxDQUFDO0lBRUQsV0FBVztJQUNKLDhCQUE4QixDQUFDLFVBQWtCO1FBQ3RELE1BQU0sVUFBVSxHQUFHLElBQUksQ0FBQyxHQUFHLENBQUMsa0JBQWtCLENBQUMsVUFBVSxDQUFDLENBQUE7UUFDMUQsT0FBTyxVQUFVLENBQUM7SUFDcEIsQ0FBQztDQUVGO0FBckRELHdCQXFEQztBQUVELGtCQUFlLE1BQU0sQ0FBQSJ9 \ No newline at end of file diff --git a/build/main/core/QOSRpc.spec.js b/build/main/core/QOSRpc.spec.js index f217b7d..d6757b8 100644 --- a/build/main/core/QOSRpc.spec.js +++ b/build/main/core/QOSRpc.spec.js @@ -5,42 +5,51 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", { value: true }); const ava_1 = __importDefault(require("ava")); // import nacl from 'tweetnacl'; -const QOSRpc_1 = __importDefault(require("./QOSRpc")); +// import QOSRpc from './QOSRpc'; // import { IApproveInput } from './Txs/Approve'; // import { ITransferInput } from './Txs/Bank'; // import { IModifyDelegationInput, IUnbondDelegationInput } from './Txs/Delegation'; // import { IBase } from './types/IBaseInput'; -const utils_1 = require("./utils"); +// import { encodeBase64 } from './utils'; // import { decodeBase64, encodeBase64 } from './utils'; -const log_1 = __importDefault(require("./utils/log")); +// import logger from './utils/log'; +require('qosKeys'); ava_1.default('qosrpc test', async (t) => { - log_1.default.debug('1'); - const rpc = new QOSRpc_1.default({ baseUrl: 'http://47.100.168.251:9876' }); + // logger.debug('1') + // const rpc = new QOSRpc({ baseUrl: 'http://47.100.168.251:9876' }) + // const rpc = new QOSRpc({ baseUrl: 'http://47.98.253.9:9876' }) // const Mn = rpc.generateMnemonic() // logger.debug('Mn', Mn) // const account = rpc.recoveryAccountByPrivateKey('0mvLfssOE8FN4m2xuzlw1wfC8AKEigZyHyQwQLag9RDSs8G8VniIEnJSmlZWNGDZsR6jBq5c/NY5xcWlUr0J3w==') - const account = rpc.importAccount('violin discover song model crawl distance method guess twenty silly chaos skirt convince hero oxygen cabin palm tomato wing dolphin chief clock cradle tackle'); + // const account = rpc.importAccount('giant tackle detail dignity catalog broccoli lady harbor dad mosquito right answer') // const account = rpc.importAccount(Mn) - // logger.debug(account.address) - log_1.default.debug('keyPair.publicKey', (account.keypair.publicKey).join(',')); - log_1.default.debug('keyPair.publicKey encodeBase64', utils_1.encodeBase64(account.keypair.publicKey)); - log_1.default.debug('keyPair.secretKey', (account.keypair.privateKey).join(',')); - log_1.default.debug('keyPair.secretKey encodeBase64', utils_1.encodeBase64(account.keypair.privateKey)); - log_1.default.debug('keyPair.bech32pubkey', account.keypair.bech32pubkey); - log_1.default.debug(account.pubKey); + // console.log(account) + // const [hexprikey, pubkey, accaddr, prikeyBz, pubkeyBz, err] = (global as any).qosKeys.DeriveQOSKey('giant tackle detail dignity catalog broccoli lady harbor dad mosquito right answer'); + // console.log('----', hexprikey) + // console.log('----', pubkey) + // console.log('----', accaddr) + // console.log('----', prikeyBz) + // console.log('----', pubkeyBz) + // console.log(err) + // logger.debug('keyPair.publicKey', (account.keypair.publicKey).join(',')) + // logger.debug('keyPair.publicKey encodeBase64', encodeBase64(account.keypair.publicKey)) + // logger.debug('keyPair.secretKey', (account.keypair.privateKey).join(',')) + // logger.debug('keyPair.secretKey encodeBase64', encodeBase64(account.keypair.privateKey)) + // logger.debug('keyPair.bech32pubkey', account.keypair.bech32pubkey) + // logger.debug(account.pubKey) // try { // const res = await rpc.tx.sendTx() // logger.debug(JSON.stringify(res.data)) // const myBase: IBase = { // from: account.address, - // chain_id: 'aquarius-2001', + // chain_id: 'qos-test', // max_gas: '200000', // } // const obj: ITransferInput = { - // qos: '1111', + // qos: '1000', // base: myBase, // } - // const res00 = await account.sendTransferTx('qosacc18j9ncemyh0jex3k2yu3s6zh53azfsgxav7t3wq', obj) + // await account.sendTransferTx('qosacc1edth0vln3dch80c08adt0pas4vqxnr2u3yf04n', obj) // logger.debug('Transfer result', res00) // const del: ICreateDelegationInput= { // amount: '1111', @@ -71,18 +80,16 @@ ava_1.default('qosrpc test', async (t) => { // logger.debug('Unbond all Delegation result', res04) // logger.debug('Unbond all Delegation result:', res04.status, ', hash:', res04.data.hash) // ------test query------ - const res05 = await account.queryDelagationAll(account.address); - log_1.default.debug('Query all Delegation result data :', res05.data); - log_1.default.debug('Query all Delegation result status :', res05.status); - const res06 = await account.queryDelagationOne(account.address, 'qosval19hrl38w5lm6sklw2hzrzrjtsxudpy8hyfaea3e'); - log_1.default.debug('Query one Delegation result data :', res06.data); - log_1.default.debug('Query one Delegation result status :', res06.status); - const res07 = await account.queryValidatorOne('qosval19hrl38w5lm6sklw2hzrzrjtsxudpy8hyfaea3e'); - log_1.default.debug('Query one Validator result data :', res07.data); - log_1.default.debug('Query one Validator result status :', res07.status); - const res08 = await account.queryAccount(account.address); - log_1.default.debug('Query account result data :', res08.data); - log_1.default.debug('Query account result status :', res08.status); + // const res05 = await account.queryDelagationAll(account.address) + // logger.debug('Query all Delegation result data :', res05.data) + // logger.debug('Query all Delegation result status :', res05.status) + // const res06 = await account.queryDelagationOne(account.address, 'qosval19hrl38w5lm6sklw2hzrzrjtsxudpy8hyfaea3e') + // logger.debug('Query one Delegation result data :', res06.data) + // logger.debug('Query one Delegation result status :', res06.status) + // const res07 = await account.queryValidatorOne('qosval19hrl38w5lm6sklw2hzrzrjtsxudpy8hyfaea3e') + // logger.debug('Query one Validator result data :', res07.data) + // logger.debug('Query one Validator result status :', res07.status) + // const res08 = await account.queryAccount(account.address) // const res01 = await account.sendCheckTx(obj) // logger.debug('check result', res01) // const approveObj: IApproveInput = { @@ -101,4 +108,4 @@ ava_1.default('qosrpc test', async (t) => { // } t.pass(); }); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUU9TUnBjLnNwZWMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvY29yZS9RT1NScGMuc3BlYy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLDhDQUF1QjtBQUN2QixnQ0FBZ0M7QUFDaEMsc0RBQThCO0FBQzlCLGlEQUFpRDtBQUNqRCwrQ0FBK0M7QUFDL0MscUZBQXFGO0FBQ3JGLDhDQUE4QztBQUM5QyxtQ0FBdUM7QUFDdkMsd0RBQXdEO0FBQ3hELHNEQUFpQztBQUVqQyxhQUFJLENBQUMsYUFBYSxFQUFFLEtBQUssRUFBQyxDQUFDLEVBQUMsRUFBRTtJQUM1QixhQUFNLENBQUMsS0FBSyxDQUFDLEdBQUcsQ0FBQyxDQUFBO0lBRWpCLE1BQU0sR0FBRyxHQUFHLElBQUksZ0JBQU0sQ0FBQyxFQUFFLE9BQU8sRUFBRSw0QkFBNEIsRUFBRSxDQUFDLENBQUE7SUFFakUsb0NBQW9DO0lBQ3BDLHlCQUF5QjtJQUN6Qiw4SUFBOEk7SUFDOUksTUFBTSxPQUFPLEdBQUcsR0FBRyxDQUFDLGFBQWEsQ0FBQywrSkFBK0osQ0FBQyxDQUFBO0lBQ2xNLHdDQUF3QztJQUN4QyxnQ0FBZ0M7SUFDaEMsYUFBTSxDQUFDLEtBQUssQ0FBQyxtQkFBbUIsRUFBRSxDQUFDLE9BQU8sQ0FBQyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUMsSUFBSSxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUE7SUFDeEUsYUFBTSxDQUFDLEtBQUssQ0FBQyxnQ0FBZ0MsRUFBRSxvQkF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0Q7SUFDdEQsMEZBQTBGO0lBRTFGLHlCQUF5QjtJQUN6QixrRUFBa0U7SUFDbEUsaUVBQWlFO0lBQ2pFLHFFQUFxRTtJQUVyRSxtSEFBbUg7SUFDbkgsaUVBQWlFO0lBQ2pFLHFFQUFxRTtJQUVyRSxpR0FBaUc7SUFDakcsZ0VBQWdFO0lBQ2hFLG9FQUFvRTtJQUVwRSw0REFBNEQ7SUFJNUQsK0NBQStDO0lBQy9DLHNDQUFzQztJQUV0QyxzQ0FBc0M7SUFDdEMsaUJBQWlCO0lBQ2pCLGtCQUFrQjtJQUNsQixJQUFJO0lBRUoseUdBQXlHO0lBQ3pHLHdDQUF3QztJQUV4Qyx5R0FBeUc7SUFDekcsd0NBQXdDO0lBRXhDLDhGQUE4RjtJQUM5Riw4QkFBOEI7SUFDOUIsa0NBQWtDO0lBQ2xDLG9CQUFvQjtJQUNwQix3QkFBd0I7SUFDeEIsSUFBSTtJQUVKLENBQUMsQ0FBQyxJQUFJLEVBQUUsQ0FBQTtBQUNWLENBQUMsQ0FBQyxDQUFDIn0= \ No newline at end of file diff --git a/build/main/core/SecretKey.d.ts b/build/main/core/SecretKey.d.ts index b4f3575..a9a9442 100644 --- a/build/main/core/SecretKey.d.ts +++ b/build/main/core/SecretKey.d.ts @@ -1,17 +1,10 @@ -/// +import { IAcc } from './types/common'; export default class SecretKey { generateMnemonic(): string; - genarateKeyPair(mnemonic: string): { - publicKey: any; - privateKey: any; - bech32pubkey: any; - }; + genarateKeyPair(mnemonic: string): IAcc; + recoveryKeyPair(privateKey: string): IAcc; + verifyBech32String(accAddress: string): any; getBech32PubKey(publicKey: any): any; - recoveryKeyPair(privateKey: Uint8Array): { - publicKey: Buffer; - privateKey: Uint8Array; - bech32pubkey: any; - }; test(): void; getAddress(publicKey: Uint8Array): any; } diff --git a/build/main/core/SecretKey.js b/build/main/core/SecretKey.js index f8aae3e..e9d1964 100644 --- a/build/main/core/SecretKey.js +++ b/build/main/core/SecretKey.js @@ -2,7 +2,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); const bip39_1 = require("bip39"); require('qosKeys'); -const utils_1 = require("./utils"); class SecretKey { generateMnemonic() { // 商 256,生成24个助记单词, 商 128,生成12个助记单词 @@ -10,23 +9,35 @@ class SecretKey { return mnemonic; } genarateKeyPair(mnemonic) { - // const seed = mnemonicToSeedSync(mnemonic); - // 从助记词中获取私钥种子 - const [prikeyBz, pubkeyBz, err] = global.qosKeys.DeriveQOSKey(mnemonic); - // const [privateSeed, err] = (global as any).hdpath.DerivePrivateKeyForPath(secret, chaincode, "44'/389'/0'/0/0") - if (err != null) { - // tslint:disable-next-line: no-console - console.log(err); - } - // const secret256 = getHash256(privateSeed); - // const keyPair = ed25519.createKeyPair(new Buffer(secret256)); - // keyPair.bech32pubkey = this.getBech32PubKey(keyPair.publicKey) + // 根据助记词得到账户信息 + // @ts-ignore + const [hexprikey, pubkey, accaddr, prikeyBz, pubkeyBz, err] = global.qosKeys.DeriveQOSKey(mnemonic); + return { + address: accaddr, + keyPair: { + hexPrivateKey: hexprikey, + privateKey: prikeyBz, + pubKey: pubkeyBz + } + }; + } + recoveryKeyPair(privateKey) { + // 根据私钥得到账户信息 + // @ts-ignore + const [hexprikey, pubkey, accaddr, prikeyBz, pubkeyBz, err] = global.qosKeys.RecoverFromPrivateKey(privateKey); return { - publicKey: pubkeyBz, - privateKey: prikeyBz, - bech32pubkey: this.getBech32PubKey(pubkeyBz) + address: accaddr, + keyPair: { + hexPrivateKey: hexprikey, + privateKey: prikeyBz, + pubKey: pubkeyBz + } }; } + verifyBech32String(accAddress) { + const isValidate = global.qosKeys.VerifyBech32String(accAddress); + return isValidate; + } getBech32PubKey(publicKey) { const [bech32pubkey, err2] = global.qosKeys.Bech32ifyQOSAccPubKey(publicKey); if (err2 != null) { @@ -34,14 +45,6 @@ class SecretKey { } return bech32pubkey; } - recoveryKeyPair(privateKey) { - const publicKey = utils_1.stringToBuffer(utils_1.buf2hex(privateKey).substring(64, 128), 'hex'); - return { - publicKey, - privateKey, - bech32pubkey: this.getBech32PubKey(publicKey) - }; - } test() { // return keyPair } @@ -58,4 +61,4 @@ class SecretKey { } } exports.default = SecretKey; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiU2VjcmV0S2V5LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2NvcmUvU2VjcmV0S2V5LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQ0EsaUNBQXlDO0FBQ3pDLE9BQU8sQ0FBQyxTQUFTLENBQUMsQ0FBQztBQUNuQixtQ0FBa0Q7QUFFbEQsTUFBcUIsU0FBUztJQUNyQixnQkFBZ0I7UUFDckIsbUNBQW1DO1FBQ25DLE1BQU0sUUFBUSxHQUFHLHdCQUFnQixDQUFDLEdBQUcsQ0FBQyxDQUFDO1FBQ3ZDLE9BQU8sUUFBUSxDQUFDO0lBQ2xCLENBQUM7SUFFTSxlQUFlLENBQUMsUUFBZ0I7UUFDckMsNkNBQTZDO1FBQzdDLGNBQWM7UUFDZCxNQUFNLENBQUMsUUFBUSxFQUFFLFFBQVEsRUFBRSxHQUFHLENBQUMsR0FBSSxNQUFjLENBQUMsT0FBTyxDQUFDLFlBQVksQ0FBQyxRQUFRLENBQUMsQ0FBQztRQUNqRixrSEFBa0g7UUFFbEgsSUFBSSxHQUFHLElBQUksSUFBSSxFQUFFO1lBQ2YsdUNBQXVDO1lBQ3ZDLE9BQU8sQ0FBQyxHQUFHLENBQUMsR0FBRyxDQUFDLENBQUE7U0FDakI7UUFDRCw2Q0FBNkM7UUFDN0MsZ0VBQWdFO1FBQ2hFLGlFQUFpRTtRQUNqRSxPQUFPO1lBQ0wsU0FBUyxFQUFFLFFBQVE7WUFDbkIsVUFBVSxFQUFFLFFBQVE7WUFDcEIsWUFBWSxFQUFFLElBQUksQ0FBQyxlQUFlLENBQUMsUUFBUSxDQUFDO1NBQzdDLENBQUE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Approve.js +++ b/build/main/core/Txs/Approve.js @@ -17,7 +17,6 @@ const sign_1 = require("../common/sign"); const Tx_1 = __importDefault(require("./Tx")); async function sendTx(target, result) { const res = await target.sendTx({ tx: result }); - // logger.debug(res) return res; } class Approve extends Tx_1.default { @@ -90,4 +89,4 @@ __decorate([ __metadata("design:returntype", Promise) ], Approve.prototype, "execUseApproveTx", null); exports.default = Approve; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQXBwcm92ZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9jb3JlL1R4cy9BcHByb3ZlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7O0FBQ0EsbURBQTRDO0FBQzVDLHlDQUFtRDtBQUluRCw4Q0FBc0I7QUFPdEIsS0FBSyxVQUFVLE1BQU0sQ0FBQyxNQUFlLEVBQUUsTUFBVztJQUM5QyxNQUFNLEdBQUcsR0FBRyxNQUFNLE1BQU0sQ0FBQyxNQUFNLENBQUMsRUFBRSxFQUFFLEVBQUUsTUFBTSxFQUFFLENBQUMsQ0FBQTtJQUMvQyxvQkFBb0I7SUFDcEIsT0FBTyxHQUFHLENBQUE7QUFDZCxDQUFDO0FBRUQsTUFBcUIsT0FBUSxTQUFRLFlBQUU7SUFDbkMsWUFBWSxHQUFXLEVBQUUsT0FBZ0I7UUFDdkMsS0FBSyxDQUFDLEdBQUcsRUFBRSxPQUFPLENBQUMsQ0FBQTtJQUNyQixDQUFDO0lBR0ksS0FBSyxDQUFDLGFBQWEsQ0FBQyxPQUFlLEVBQUUsSUFBbUI7UUFDN0QsTUFBTSxHQUFHLEdBQUcsTUFBTSxJQUFJLENBQUMsR0FBRyxDQUFDLE9BQU8sQ0FBQztZQUNqQyxNQUFNLEVBQUUsTUFBTTtZQUNkLEdBQUcsRUFBRSxxQkFBcUIsT0FBTyxrQkFBa0I7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UFBRSxNQUFNO1lBQ2QsR0FBRyxFQUFFLHFCQUFxQixPQUFPLG9CQUFvQjtZQUNyRCxJQUFJO1NBQ0wsQ0FBQyxDQUFBO1FBQ0YsT0FBTyxHQUFHLENBQUE7SUFDWixDQUFDO0lBR00sS0FBSyxDQUFDLGdCQUFnQixDQUFDLE9BQWUsRUFBRSxJQUFtQjtRQUNoRSxNQUFNLEdBQUcsR0FBRyxNQUFNLElBQUksQ0FBQyxHQUFHLENBQUMsT0FBTyxDQUFDO1lBQ2pDLE1BQU0sRUFBRSxNQUFNO1lBQ2QsR0FBRyxFQUFFLHFCQUFxQixPQUFPLGVBQWU7WUFDaEQsSUFBSTtTQUNMLENBQUMsQ0FBQTtRQUNGLE9BQU8sR0FBRyxDQUFBO0lBQ1osQ0FBQztDQUNGO0FBL0NDO0lBREMsaUJBQUssQ0FBQyx3QkFBaUIsRUFBRSxNQUFNLENBQUM7Ozs7NENBUWhDO0FBR0Q7SUFEQyxpQkFBSyxDQUFDLHdCQUFpQixFQUFFLE1BQU0sQ0FBQzs7OztrREFRaEM7QUFZRDtJQURDLGlCQUFLLENBQUMsd0JBQWlCLEVBQUUsTUFBTSxDQUFDOzs7O29EQVFoQztBQUdEO0lBREMsaUJBQUssQ0FBQyx3QkFBaUIsRUFBRSxNQUFNLENBQUM7Ozs7K0NBUWhDO0FBcERILDBCQXFEQyJ9 \ No newline at end of file diff --git a/build/main/core/Txs/Bank.js b/build/main/core/Txs/Bank.js index 3568bb0..eac2b58 100644 --- a/build/main/core/Txs/Bank.js +++ b/build/main/core/Txs/Bank.js @@ -14,11 +14,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", { value: true }); const decorator_1 = require("../common/decorator"); const sign_1 = require("../common/sign"); -const log_1 = __importDefault(require("../utils/log")); const Tx_1 = __importDefault(require("./Tx")); async function sendTx(target, result) { const res = await target.sendTx({ tx: result }); - log_1.default.debug('res in Bank sendTX ', res); return res; } class Bank extends Tx_1.default { @@ -27,7 +25,6 @@ class Bank extends Tx_1.default { } async execTransferTx(address, data) { const res = await this.rpc.post(`/bank/accounts/${address}/transfers`, data); - log_1.default.debug('execTransfer result', res); return res; } async execCheckTx(data) { @@ -38,7 +35,6 @@ class Bank extends Tx_1.default { } async execQueryAccount(accountAddress) { const res = await this.rpc.get(`/accounts/${accountAddress}`); - log_1.default.debug('execQueryAccount result', res); return res; } } @@ -55,4 +51,4 @@ __decorate([ __metadata("design:returntype", Promise) ], Bank.prototype, "execCheckTx", null); exports.default = Bank; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQmFuay5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9jb3JlL1R4cy9CYW5rLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7O0FBQ0EsbURBQTRDO0FBQzVDLHlDQUFtRDtBQUluRCx1REFBa0M7QUFDbEMsOENBQXNCO0FBT3RCLEtBQUssVUFBVSxNQUFNLENBQUMsTUFBWSxFQUFFLE1BQVc7SUFDN0MsTUFBTSxHQUFHLEdBQUcsTUFBTSxNQUFNLENBQUMsTUFBTSxDQUFDLEVBQUUsRUFBRSxFQUFFLE1BQU0sRUFBRSxDQUFDLENBQUE7SUFDL0MsYUFBTSxDQUFDLEtBQUssQ0FBQyxxQkFBcUIsRUFBRSxHQUFHLENBQUMsQ0FBQTtJQUN4QyxPQUFPLEdBQUcsQ0FBQTtBQUNaLENBQUM7QUFFRCxNQUFxQixJQUFLLFNBQVEsWUFBRTtJQUNsQyxZQUFZLEdBQVcsRUFBRSxPQUFnQjtRQUN2QyxLQUFLLENBQUMsR0FBRyxFQUFFLE9BQU8sQ0FBQyxDQUFBO0lBQ3JCLENBQUM7SUFHTSxLQUFLLENBQUMsY0FBYyxDQUFDLE9BQWUsRUFBRSxJQUFvQjtRQUMvRCxNQUFNLEdBQUcs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RUFBRSxDQUNoQyxDQUFBO1FBQ0QsT0FBTyxHQUFHLENBQUE7SUFDWixDQUFDO0NBRUY7QUExQkM7SUFEQyxpQkFBSyxDQUFDLHdCQUFpQixFQUFFLE1BQU0sQ0FBQzs7OzswQ0FPaEM7QUFHRDtJQURDLGlCQUFLLENBQUMsd0JBQWlCLEVBQUUsTUFBTSxDQUFDOzs7O3VDQVNoQztBQXZCSCx1QkFnQ0MifQ== \ No newline at end of file diff --git a/build/main/core/Txs/Delegation.d.ts b/build/main/core/Txs/Delegation.d.ts index dfedb9d..7602283 100644 --- a/build/main/core/Txs/Delegation.d.ts +++ b/build/main/core/Txs/Delegation.d.ts @@ -20,5 +20,6 @@ export default class Delegation extends Tx { execUnbondDelegationTx(validatorAddress: string, data: IUnbondDelegationInput): Promise>; execQueryDelegationAll(delegatorAddress: string): Promise>; execQueryDelegationOne(delegatorAddress: string, validatorAddress: string): Promise>; + execQueryValidatorAll(): Promise>; execQueryValidatorOne(validatorAddress: string): Promise>; } diff --git a/build/main/core/Txs/Delegation.js b/build/main/core/Txs/Delegation.js index 9b6286a..0b89d1c 100644 --- a/build/main/core/Txs/Delegation.js +++ b/build/main/core/Txs/Delegation.js @@ -14,11 +14,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", { value: true }); const decorator_1 = require("../common/decorator"); const sign_1 = require("../common/sign"); -const log_1 = __importDefault(require("../utils/log")); const Tx_1 = __importDefault(require("./Tx")); async function sendTx(target, result) { const res = await target.sendTx({ tx: result }); - log_1.default.debug('res in sendTX ', res); return res; } class Delegation extends Tx_1.default { @@ -27,32 +25,30 @@ class Delegation extends Tx_1.default { } async execCreateDelegationTx(validatorAddress, data) { const res = await this.rpc.post(`/stake/delegators/${validatorAddress}/delegations`, data); - log_1.default.debug('execCreateDelegate result', res); return res; } async execModifyDelegationTx(validatorAddress, data) { const res = await this.rpc.post(`/stake/delegators/${validatorAddress}/modify_delegations`, data); - log_1.default.debug('execModifyDelegation result', res); return res; } async execUnbondDelegationTx(validatorAddress, data) { const res = await this.rpc.post(`/stake/delegators/${validatorAddress}/unbond_delegations`, data); - log_1.default.debug('execUnbondDelegation result', res); return res; } async execQueryDelegationAll(delegatorAddress) { const res = await this.rpc.get(`/stake/delegators/${delegatorAddress}/delegations`); - log_1.default.debug('QueryDelegationsAll result', res); return res; } async execQueryDelegationOne(delegatorAddress, validatorAddress) { const res = await this.rpc.get(`/stake/delegators/${delegatorAddress}/validators/${validatorAddress}`); - log_1.default.debug('QueryDelegationOne result', res); + return res; + } + async execQueryValidatorAll() { + const res = await this.rpc.get('/stake/validators'); return res; } async execQueryValidatorOne(validatorAddress) { const res = await this.rpc.get(`/stake/validators/${validatorAddress}`); - log_1.default.debug('QueryValidatorOne result', res); return res; } } @@ -75,4 +71,4 @@ __decorate([ __metadata("design:returntype", Promise) ], Delegation.prototype, "execUnbondDelegationTx", null); exports.default = Delegation; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRGVsZWdhdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9jb3JlL1R4cy9EZWxlZ2F0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7O0FBQ0EsbURBQTRDO0FBQzVDLHlDQUFtRDtBQUduRCx1REFBa0M7QUFDbEMsOENBQXNCO0FBZ0J0QixLQUFLLFVBQVUsTUFBTSxDQUFDLE1BQWtCLEVBQUUsTUFBVztJQUNuRCxNQUFNLEdBQUcsR0FBRyxNQUFNLE1BQU0sQ0FBQyxNQUFNLENBQUMsRUFBRSxFQUFFLEVBQUUsTUFBTSxFQUFFLENBQUMsQ0FBQTtJQUMvQyxhQUFNLENBQUMsS0FBSyxDQUFDLGdCQUFnQixFQUFFLEdBQUcsQ0FBQyxDQUFBO0lBQ25DLE9BQU8sR0FBRyxDQUFBO0FBQ1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SxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQzVCLHFCQUFxQixnQkFBZ0IsRUFBRSxDQUN4QyxDQUFBO1FBQ0QsT0FBTyxHQUFHLENBQUE7SUFDWixDQUFDO0NBSUY7QUF4REM7SUFEQyxpQkFBSyxDQUFDLHdCQUFpQixFQUFFLE1BQU0sQ0FBQzs7Ozt3REFPaEM7QUFHRDtJQURDLGlCQUFLLENBQUMsd0JBQWlCLEVBQUUsTUFBTSxDQUFDOzs7O3dEQU9oQztBQUdEO0lBREMsaUJBQUssQ0FBQyx3QkFBaUIsRUFBRSxNQUFNLENBQUM7Ozs7d0RBT2hDO0FBOUJILDZCQThEQyJ9 \ No newline at end of file diff --git a/build/main/core/Txs/Tx.js b/build/main/core/Txs/Tx.js index 28a0ef7..ad84cda 100644 --- a/build/main/core/Txs/Tx.js +++ b/build/main/core/Txs/Tx.js @@ -1,16 +1,11 @@ "use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; Object.defineProperty(exports, "__esModule", { value: true }); -const log_1 = __importDefault(require("../utils/log")); class Tx { constructor(rpc, account) { this.rpc = rpc; this.account = account; } async sendTx({ tx, mode = 'block' }) { - log_1.default.debug('sendTx:===', JSON.stringify({ tx, mode })); const res = await this.rpc.request({ method: 'POST', url: '/txs', @@ -20,4 +15,4 @@ class Tx { } } exports.default = Tx; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiVHguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvY29yZS9UeHMvVHgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFFQSx1REFBa0M7QUFFbEMsTUFBcUIsRUFBRTtJQUdyQixZQUFZLEdBQVcsRUFBRSxPQUFnQjtRQUN2QyxJQUFJLENBQUMsR0FBRyxHQUFHLEdBQUcsQ0FBQztRQUNmLElBQUksQ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sRUFBb0Q7UUFDMUYsTUFBTSxHQUFHLEdBQUcsTUFBTyxJQUFJLENBQUMsR0FBRyxDQUFDLE9BQU8sQ0FBQztZQUNsQyxNQUFNLEVBQUUsTUFBTTtZQUNkLEdBQUcsRUFBRSxNQUFNO1lBQ1gsSUFBSSxFQUFFLEVBQUUsRUFBRSxFQUFFLElBQUksRUFBRTtTQUNuQixDQUFDLENBQUMsS0FBSyxDQUFDLEdBQUcsQ0FBQyxFQUFFLENBQUMsT0FBTyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFBO1FBQ2pDLE9BQU8sR0FBRyxDQUFBO0lBQ1osQ0FBQztDQUNGO0FBaEJELHFCQWdCQyJ9 \ No newline at end of file diff --git a/build/main/core/common/decorator.d.ts b/build/main/core/common/decorator.d.ts index 16c0abf..ba5c036 100644 --- a/build/main/core/common/decorator.d.ts +++ b/build/main/core/common/decorator.d.ts @@ -1 +1 @@ -export declare function after(...args: any[]): (_target: any, name: any, descriptor: any) => any; +export declare function after(...args: any[]): (_target: any, _key: any, descriptor: any) => any; diff --git a/build/main/core/common/decorator.js b/build/main/core/common/decorator.js index 3ce17de..2b38231 100644 --- a/build/main/core/common/decorator.js +++ b/build/main/core/common/decorator.js @@ -1,17 +1,12 @@ "use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; Object.defineProperty(exports, "__esModule", { value: true }); -const log_1 = __importDefault(require("../utils/log")); function after(...args) { - return (_target, name, descriptor) => { + return (_target, _key, descriptor) => { // 获取value,其实就是原函数 const oldValue = descriptor.value; // 将value重新赋值一个函数 descriptor.value = async function () { // tslint:disable-next-line: no-console - log_1.default.debug(`Calling ${name} with`, arguments); // 将原本的函数执行一下,apply改变this的指向 const val = await oldValue.apply(this, arguments); let result = val; @@ -24,4 +19,4 @@ function after(...args) { }; } exports.after = after; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxl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zIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL2NvcmUvY29tbW9uL2RlY29yYXRvci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLFNBQWdCLEtBQUssQ0FBQyxHQUFHLElBQUk7SUFDM0IsT0FBTyxDQUFDLE9BQU8sRUFBRSxJQUFJLEVBQUUsVUFBVSxFQUFFLEVBQUU7UUFDbkMsa0JBQWtCO1FBQ2xCLE1BQU0sUUFBUSxHQUFHLFVBQVUsQ0FBQyxLQUFLLENBQUM7UUFDbEMsaUJBQWlCO1FBQ2pCLFVBQVUsQ0FBQyxLQUFLLEdBQUcsS0FBSztZQUN0Qix1Q0FBdUM7WUFDdkMsNEJBQTRCO1lBQzVCLE1BQU0sR0FBRyxHQUFHLE1BQU0sUUFBUSxDQUFDLEtBQUssQ0FBQyxJQUFJLEVBQUUsU0FBUyxDQUFDLENBQUE7WUFDakQsSUFBSSxNQUFNLEdBQUcsR0FBRyxDQUFDO1lBQ2pCLEtBQUssTUFBTSxRQUFRLElBQUksSUFBSSxFQUFFO2dCQUMzQixNQUFNLEdBQUcsQ0FBQyxNQUFNLFFBQVEsQ0FBQyxJQUFJLEVBQUUsTUFBTSxFQUFFLEdBQUcsU0FBUyxDQUFDLENBQUMsSUFBSSxNQUFNLENBQUE7YUFDaEU7WUFDRCxPQUFPLE1BQU0sQ0FBQztRQUNoQixDQUFDLENBQUM7UUFFRixPQUFPLFVBQVUsQ0FBQztJQUNwQixDQUFDLENBQUE7QUFDSCxDQUFDO0FBbEJELHNCQWtCQyJ9 \ No newline at end of file diff --git a/build/main/core/common/sign.d.ts b/build/main/core/common/sign.d.ts index 19336fd..0166e21 100644 --- a/build/main/core/common/sign.d.ts +++ b/build/main/core/common/sign.d.ts @@ -1,4 +1,4 @@ import Account from '../Account'; import Tx from '../Txs/Tx'; export declare function sign(account: Account, data: any): string; -export declare function componentSignData(target: Tx, res: any): any; +export declare function componentSignData(target: Tx, res: any): Promise; diff --git a/build/main/core/common/sign.js b/build/main/core/common/sign.js index 2478e09..c07f998 100644 --- a/build/main/core/common/sign.js +++ b/build/main/core/common/sign.js @@ -1,35 +1,28 @@ "use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; Object.defineProperty(exports, "__esModule", { value: true }); // import ed25519 from 'supercop.js' // import nacl from 'tweetnacl'; require('qosKeys'); const utils_1 = require("../utils"); -const log_1 = __importDefault(require("../utils/log")); function sign(account, data) { // const sig = nacl.sign.detached(decodeBase64(data), account.keypair.privateKey) // const sig = ed25519.Sign(decodeBase64(data), account.keypair.privateKey); - const sig = global.qosKeys.Sign(account.keypair.privateKey, utils_1.decodeBase64(data)); + const sig = global.qosKeys.SignBase64Message(account.keypair.hexPrivateKey, data); // logger.debug('sig', encodeBase64(sig)) return utils_1.encodeBase64(sig); } exports.sign = sign; -function componentSignData(target, res) { +async function componentSignData(target, res) { const sig = sign(target.account, res.data.sign_bytes); const resObj = JSON.parse(res.data.tx); - log_1.default.debug('target', target); - log_1.default.debug('res', res); + const pubkeyBase64 = global.qosKeys.EncodeBase64(target.account.pubKeyBz); resObj.value.sigature[0].signature = sig; resObj.value.sigature[0].pubkey = { type: 'tendermint/PubKeyEd25519', // 'value': 'lDomDLEe+ou01k4FsNLJOdU10rhlpBxVQR+BAwSpUzc=' - value: target.account.pubKey + value: pubkeyBase64 }; - log_1.default.debug('resobj', resObj); - log_1.default.debug('itx', resObj.value.itx[0]); return resObj; } exports.componentSignData = componentSignData; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2lnbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9jb3JlL2NvbW1vbi9zaWduLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUEsb0NBQW9DO0FBQ3BDLGdDQ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QyxJQUFJLENBQUMsVUFBVSxDQUFDLENBQUE7SUFDOUQsTUFBTSxNQUFNLEdBQUcsSUFBSSxDQUFDLEtBQUssQ0FBQyxHQUFHLENBQUMsSUFBSSxDQUFDLEVBQUUsQ0FBQyxDQUFBO0lBQ3RDLE1BQU0sWUFBWSxHQUFJLE1BQWMsQ0FBQyxPQUFPLENBQUMsWUFBWSxDQUFDLE1BQU0sQ0FBQyxPQUFPLENBQUMsUUFBUSxDQUFDLENBQUE7SUFFbEYsTUFBTSxDQUFDLEtBQUssQ0FBQyxRQUFRLENBQUMsQ0FBQyxDQUFDLENBQUMsU0FBUyxHQUFHLEdBQUcsQ0FBQTtJQUN4QyxNQUFNLENBQUMsS0FBSyxDQUFDLFFBQVEsQ0FBQyxDQUFDLENBQUMsQ0FBQyxNQUFNLEdBQUc7UUFDaEMsSUFBSSxFQUFFLDBCQUEwQjtRQUNoQywwREFBMEQ7UUFDMUQsS0FBSyxFQUFFLFlBQVk7S0FDcEIsQ0FBQTtJQUNELE9BQU8sTUFBTSxDQUFBO0FBQ2YsQ0FBQztBQVpELDhDQVlDIn0= \ No newline at end of file diff --git a/build/main/core/types/common.d.ts b/build/main/core/types/common.d.ts index 421cf3a..298d3d6 100644 --- a/build/main/core/types/common.d.ts +++ b/build/main/core/types/common.d.ts @@ -1,7 +1,11 @@ export interface IKeyPair { - publicKey: Uint8Array; privateKey: Uint8Array; - bech32pubkey: string; + pubKey: Uint8Array; + hexPrivateKey: string; +} +export interface IAcc { + address: string; + keyPair: IKeyPair; } export interface IQSC { coin_name: string; diff --git a/build/main/core/utils/log.d.ts b/build/main/core/utils/log.d.ts deleted file mode 100644 index e45f12d..0000000 --- a/build/main/core/utils/log.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import log4js from 'log4js'; -declare const logger: log4js.Logger; -export default logger; diff --git a/build/main/core/utils/log.js b/build/main/core/utils/log.js deleted file mode 100644 index 0982bd3..0000000 --- a/build/main/core/utils/log.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const log4js_1 = __importDefault(require("log4js")); -log4js_1.default.configure({ - appenders: { log: { type: 'file', filename: 'log/log.log' } }, - categories: { default: { appenders: ['log'], level: 'debug' } } -}); -const logger = log4js_1.default.getLogger('log'); -exports.default = logger; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9nLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL2NvcmUvdXRpbHMvbG9nLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUEsb0RBQTRCO0FBQzVCLGdCQUFNLENBQUMsU0FBUyxDQUFDO0lBQ2YsU0FBUyxFQUFFLEVBQUUsR0FBRyxFQUFFLEVBQUUsSUFBSSxFQUFFLE1BQU0sRUFBRSxRQUFRLEVBQUUsYUFBYSxFQUFFLEVBQUU7SUFDN0QsVUFBVSxFQUFFLEVBQUUsT0FBTyxFQUFFLEVBQUUsU0FBUyxFQUFFLENBQUMsS0FBSyxDQUFDLEVBQUUsS0FBSyxFQUFFLE9BQU8sRUFBRSxFQUFFO0NBQ2hFLENBQUMsQ0FBQztBQUNILE1BQU0sTUFBTSxHQUFHLGdCQUFNLENBQUMsU0FBUyxDQUFDLEtBQUssQ0FBQyxDQUFDO0FBRXZDLGtCQUFlLE1BQU0sQ0FBQyJ9 \ No newline at end of file diff --git a/build/module/core/Account.d.ts b/build/module/core/Account.d.ts new file mode 100644 index 0000000..a37c64a --- /dev/null +++ b/build/module/core/Account.d.ts @@ -0,0 +1,32 @@ +import QOSRpc from './QOSRpc'; +import { IApproveInput } from './Txs/Approve'; +import { ITransferInput } from './Txs/Bank'; +import { ICreateDelegationInput, IModifyDelegationInput, IUnbondDelegationInput } from './Txs/Delegation'; +import { IAcc, IKeyPair } from './types/common'; +declare class Account { + readonly rpc: QOSRpc; + qos: number; + mnemonic: string; + keypair: IKeyPair; + address: string; + privateKey: string; + privateKeyBz: Uint8Array; + pubKeyBz: Uint8Array; + constructor(controller: QOSRpc, Acc?: IAcc, mnemonic?: string); + sendTransferTx(toAddress: string, data: ITransferInput): Promise>; + sendCreateDelegateTx(validatorAddress: string, data: ICreateDelegationInput): Promise>; + sendModifyDelegationTx(validatorAddress: string, data: IModifyDelegationInput): Promise>; + sendUnbondDelegationTx(validatorAddress: string, data: IUnbondDelegationInput): Promise>; + sendCheckTx(data: ITransferInput): Promise>; + sendApproveTx(toAddress: string, data: IApproveInput): Promise>; + sendCancelApproveTx(toAddress: string, data: IApproveInput): Promise>; + sendIncreaseApproveTx(toAddress: string, data: IApproveInput): Promise>; + sendDecreaseApproveTx(toAddress: string, data: IApproveInput): Promise>; + sendUseApproveTx(toAddress: string, data: IApproveInput): Promise>; + queryDelagationAll(deleagtorAddress: string): Promise>; + queryDelagationOne(deleagtorAddress: string, validatorAddress: string): Promise>; + queryValidatorAll(): Promise>; + queryValidatorOne(validatorAddress: string): Promise>; + queryAccount(accountAddress: any): Promise>; +} +export default Account; diff --git a/build/module/core/Account.js b/build/module/core/Account.js new file mode 100644 index 0000000..6da8268 --- /dev/null +++ b/build/module/core/Account.js @@ -0,0 +1,97 @@ +import Approve from './Txs/Approve'; +import Bank from './Txs/Bank'; +import Delegation from './Txs/Delegation'; +// import { ITransferInput } from './' +class Account { + constructor(controller, Acc, mnemonic) { + // public account: IAccount + this.qos = 0; + this.rpc = controller; + if (Acc) { + this.mnemonic = mnemonic; + this.keypair = Acc.keyPair; + this.privateKey = Acc.keyPair.hexPrivateKey; + // this.pubKey = Acc.keyPair.pubKey; + this.address = Acc.address; + this.privateKeyBz = Acc.keyPair.privateKey; + this.pubKeyBz = Acc.keyPair.pubKey; + } + } + async sendTransferTx(toAddress, data) { + const tx = new Bank(this.rpc, this); + const res = await tx.execTransferTx(toAddress, data); + return res; + } + async sendCreateDelegateTx(validatorAddress, data) { + const tx = new Delegation(this.rpc, this); + const res = await tx.execCreateDelegationTx(validatorAddress, data); + return res; + } + async sendModifyDelegationTx(validatorAddress, data) { + const tx = new Delegation(this.rpc, this); + const res = await tx.execModifyDelegationTx(validatorAddress, data); + return res; + } + async sendUnbondDelegationTx(validatorAddress, data) { + const tx = new Delegation(this.rpc, this); + const res = await tx.execUnbondDelegationTx(validatorAddress, data); + return res; + } + async sendCheckTx(data) { + const tx = new Bank(this.rpc, this); + const res = await tx.execCheckTx(data); + return res; + } + async sendApproveTx(toAddress, data) { + const tx = new Approve(this.rpc, this); + const res = await tx.execApproveTx(toAddress, data); + return res; + } + async sendCancelApproveTx(toAddress, data) { + const tx = new Approve(this.rpc, this); + const res = await tx.execCancelApproveTx(toAddress, data); + return res; + } + async sendIncreaseApproveTx(toAddress, data) { + const tx = new Approve(this.rpc, this); + const res = await tx.execIncreaseApproveTx(toAddress, data); + return res; + } + async sendDecreaseApproveTx(toAddress, data) { + const tx = new Approve(this.rpc, this); + const res = await tx.execDecreaseApproveTx(toAddress, data); + return res; + } + async sendUseApproveTx(toAddress, data) { + const tx = new Approve(this.rpc, this); + const res = await tx.execUseApproveTx(toAddress, data); + return res; + } + async queryDelagationAll(deleagtorAddress) { + const tx = new Delegation(this.rpc, this); + const res = await tx.execQueryDelegationAll(deleagtorAddress); + return res; + } + async queryDelagationOne(deleagtorAddress, validatorAddress) { + const tx = new Delegation(this.rpc, this); + const res = await tx.execQueryDelegationOne(deleagtorAddress, validatorAddress); + return res; + } + async queryValidatorAll() { + const tx = new Delegation(this.rpc, this); + const res = await tx.execQueryValidatorAll(); + return res; + } + async queryValidatorOne(validatorAddress) { + const tx = new Delegation(this.rpc, this); + const res = await tx.execQueryValidatorOne(validatorAddress); + return res; + } + async queryAccount(accountAddress) { + const tx = new Bank(this.rpc, this); + const res = await tx.execQueryAccount(accountAddress); + return res; + } +} +export default Account; +//# sourceMappingURL=data:application/json;base64,e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QOSRpc.d.ts b/build/module/core/QOSRpc.d.ts new file mode 100644 index 0000000..c4a338f --- /dev/null +++ b/build/module/core/QOSRpc.d.ts @@ -0,0 +1,27 @@ +import Account from './Account'; +import SecretKey from './SecretKey'; +import Tx from './Tx'; +import { IBaseInput } from './types/IBaseInput'; +export declare class QOSRpc { + readonly request: import("axios").AxiosInstance; + readonly tx: Tx; + config: { + readonly baseUrl: string; + }; + key: SecretKey; + private _tx; + constructor(config: { + readonly baseUrl: string; + }); + post(url: string, data: IBaseInput): Promise>; + get(url: string): Promise>; + generateMnemonic(): string; + importAccount(mnemonic: string): Account; + /** + * 根据私钥恢复账户 + * @param {string} privateKey 私钥 + */ + recoveryAccountByPrivateKey(privateKey: string): Account; + verifyBech32StringByAccAddress(accAddress: string): any; +} +export default QOSRpc; diff --git a/build/module/core/QOSRpc.js b/build/module/core/QOSRpc.js new file mode 100644 index 0000000..6559176 --- /dev/null +++ b/build/module/core/QOSRpc.js @@ -0,0 +1,47 @@ +import Account from './Account'; +import SecretKey from './SecretKey'; +import Tx from './Tx'; +import createAxioRequest from './utils/request'; +export class QOSRpc { + constructor(config) { + this.config = config; + this.key = new SecretKey(); + } + get request() { + return createAxioRequest(this.config.baseUrl); + } + get tx() { + if (!this._tx) { + this._tx = new Tx(this); + } + return this._tx; + } + post(url, data) { + return this.request.post(url, data); + } + get(url) { + return this.request.get(url); + } + generateMnemonic() { + return this.key.generateMnemonic(); + } + importAccount(mnemonic) { + const keyPair = this.key.genarateKeyPair(mnemonic); + return new Account(this, keyPair, mnemonic); + } + /** + * 根据私钥恢复账户 + * @param {string} privateKey 私钥 + */ + recoveryAccountByPrivateKey(privateKey) { + const keyPair = this.key.recoveryKeyPair(privateKey); + return new Account(this, keyPair); + } + // 账户地址格式校验 + verifyBech32StringByAccAddress(accAddress) { + const isValidate = this.key.verifyBech32String(accAddress); + return isValidate; + } +} +export default QOSRpc; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlI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VNLGdCQUFnQjtRQUNyQixPQUFPLElBQUksQ0FBQyxHQUFHLENBQUMsZ0JBQWdCLEVBQUUsQ0FBQztJQUNyQyxDQUFDO0lBRU0sYUFBYSxDQUFDLFFBQWdCO1FBQ25DLE1BQU0sT0FBTyxHQUFHLElBQUksQ0FBQyxHQUFHLENBQUMsZUFBZSxDQUFDLFFBQVEsQ0FBQyxDQUFDO1FBRW5ELE9BQU8sSUFBSSxPQUFPLENBQUMsSUFBSSxFQUFFLE9BQU8sRUFBRSxRQUFRLENBQUMsQ0FBQztJQUM5QyxDQUFDO0lBRUQ7OztPQUdHO0lBQ0ksMkJBQTJCLENBQUMsVUFBa0I7UUFDbkQsTUFBTSxPQUFPLEdBQUcsSUFBSSxDQUFDLEdBQUcsQ0FBQyxlQUFlLENBQUMsVUFBVSxDQUFDLENBQUE7UUFDcEQsT0FBTyxJQUFJLE9BQU8sQ0FBQyxJQUFJLEVBQUUsT0FBTyxDQUFDLENBQUM7SUFDcEMsQ0FBQztJQUVELFdBQVc7SUFDSiw4QkFBOEIsQ0FBQyxVQUFrQjtRQUN0RCxNQUFNLFVBQVUsR0FBRyxJQUFJLENBQUMsR0FBRyxDQUFDLGtCQUFrQixDQUFDLFVBQVUsQ0FBQyxDQUFBO1FBQzFELE9BQU8sVUFBVSxDQUFDO0lBQ3BCLENBQUM7Q0FFRjtBQUVELGVBQWUsTUFBTSxDQUFBIn0= \ No newline at end of file diff --git a/build/module/core/QOSRpc.spec.d.ts b/build/module/core/QOSRpc.spec.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/build/module/core/QOSRpc.spec.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/build/module/core/QOSRpc.spec.js b/build/module/core/QOSRpc.spec.js new file mode 100644 index 0000000..e860a21 --- /dev/null +++ b/build/module/core/QOSRpc.spec.js @@ -0,0 +1,106 @@ +import test from 'ava'; +// import nacl from 'tweetnacl'; +// import QOSRpc from './QOSRpc'; +// import { IApproveInput } from './Txs/Approve'; +// import { ITransferInput } from './Txs/Bank'; +// import { IModifyDelegationInput, IUnbondDelegationInput } from './Txs/Delegation'; +// import { IBase } from './types/IBaseInput'; +// import { encodeBase64 } from './utils'; +// import { decodeBase64, encodeBase64 } from './utils'; +// import logger from './utils/log'; +require('qosKeys'); +test('qosrpc test', async (t) => { + // logger.debug('1') + // const rpc = new QOSRpc({ baseUrl: 'http://47.100.168.251:9876' }) + // const rpc = new QOSRpc({ baseUrl: 'http://47.98.253.9:9876' }) + // const Mn = rpc.generateMnemonic() + // logger.debug('Mn', Mn) + // const account = rpc.recoveryAccountByPrivateKey('0mvLfssOE8FN4m2xuzlw1wfC8AKEigZyHyQwQLag9RDSs8G8VniIEnJSmlZWNGDZsR6jBq5c/NY5xcWlUr0J3w==') + // const account = rpc.importAccount('giant tackle detail dignity catalog broccoli lady harbor dad mosquito right answer') + // const account = rpc.importAccount(Mn) + // console.log(account) + // const [hexprikey, pubkey, accaddr, prikeyBz, pubkeyBz, err] = (global as any).qosKeys.DeriveQOSKey('giant tackle detail dignity catalog broccoli lady harbor dad mosquito right answer'); + // console.log('----', hexprikey) + // console.log('----', pubkey) + // console.log('----', accaddr) + // console.log('----', prikeyBz) + // console.log('----', pubkeyBz) + // console.log(err) + // logger.debug('keyPair.publicKey', (account.keypair.publicKey).join(',')) + // logger.debug('keyPair.publicKey encodeBase64', encodeBase64(account.keypair.publicKey)) + // logger.debug('keyPair.secretKey', (account.keypair.privateKey).join(',')) + // logger.debug('keyPair.secretKey encodeBase64', encodeBase64(account.keypair.privateKey)) + // logger.debug('keyPair.bech32pubkey', account.keypair.bech32pubkey) + // logger.debug(account.pubKey) + // try { + // const res = await rpc.tx.sendTx() + // logger.debug(JSON.stringify(res.data)) + // const myBase: IBase = { + // from: account.address, + // chain_id: 'qos-test', + // max_gas: '200000', + // } + // const obj: ITransferInput = { + // qos: '1000', + // base: myBase, + // } + // await account.sendTransferTx('qosacc1edth0vln3dch80c08adt0pas4vqxnr2u3yf04n', obj) + // logger.debug('Transfer result', res00) + // const del: ICreateDelegationInput= { + // amount: '1111', + // base: myBase, + // } + // const res01 = await account.sendCreateDelegateTx('qosval19hrl38w5lm6sklw2hzrzrjtsxudpy8hyfaea3e', del) + // // logger.debug('Create Delegation result', res01) + // logger.debug('Create Delegation result:', res01.status, ', hash:', res01.data.hash) + // const mod: IModifyDelegationInput= { + // is_compound: true, + // base: myBase, + // } + // const res02 = await account.sendModifyDelegationTx('qosval19hrl38w5lm6sklw2hzrzrjtsxudpy8hyfaea3e', mod) + // logger.debug('Modify Delegation result', res02) + // logger.debug('Modify Delegation result:', res02.status, ', hash:', res02.data.hash) + // const unbond: IUnbondDelegationInput= { + // unbond_amount: '1111', + // base: myBase, + // } + // const res03 = await account.sendUnbondDelegationTx('qosval19hrl38w5lm6sklw2hzrzrjtsxudpy8hyfaea3e', unbond) + // logger.debug('unbond Delegation result', res03) + // logger.debug('Unbond Delegation result:', res03.status, ', hash:', res03.data.hash) + // const unbond1: IUnbondDelegationInput= { + // unbond_all: true, + // base: myBase, + // } + // const res04 = await account.sendUnbondDelegationTx('qosval19hrl38w5lm6sklw2hzrzrjtsxudpy8hyfaea3e', unbond1) + // logger.debug('Unbond all Delegation result', res04) + // logger.debug('Unbond all Delegation result:', res04.status, ', hash:', res04.data.hash) + // ------test query------ + // const res05 = await account.queryDelagationAll(account.address) + // logger.debug('Query all Delegation result data :', res05.data) + // logger.debug('Query all Delegation result status :', res05.status) + // const res06 = await account.queryDelagationOne(account.address, 'qosval19hrl38w5lm6sklw2hzrzrjtsxudpy8hyfaea3e') + // logger.debug('Query one Delegation result data :', res06.data) + // logger.debug('Query one Delegation result status :', res06.status) + // const res07 = await account.queryValidatorOne('qosval19hrl38w5lm6sklw2hzrzrjtsxudpy8hyfaea3e') + // logger.debug('Query one Validator result data :', res07.data) + // logger.debug('Query one Validator result status :', res07.status) + // const res08 = await account.queryAccount(account.address) + // const res01 = await account.sendCheckTx(obj) + // logger.debug('check result', res01) + // const approveObj: IApproveInput = { + // qos: '1000', + // base: myBase, + // } + // const res10 = await account.sendApproveTx('qosacc12z5jn6c3qu3j2zy80ydwjm8pjwu3h8tqk3cwya', approveObj) + // logger.debug('Approve result', res10) + // const res11 = await account.sendApproveTx('qosacc12z5jn6c3qu3j2zy80ydwjm8pjwu3h8tqk3cwya', approveObj) + // logger.debug('Approve result', res11) + // const sig = nacl.sign.detached(decodeBase64(res.data.signBytes), account.keypair.secretKey) + // logger.debug(sig.join(',')) + // logger.debug(encodeBase64(sig)) + // } catch (error) { + // logger.error(error) + // } + t.pass(); +}); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUU9TUnBjLnNwZWMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvY29yZS9RT1NScGMuc3BlYy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLElBQUksTUFBTSxLQUFLLENBQUM7QUFDdkIsZ0NBQWdDO0FBQ2hDLGlDQUFpQztBQUNqQyxpREFBaUQ7QUFDakQsK0NBQStDO0FBQy9DLHFGQUFxRjtBQUNyRiw4Q0FBOEM7QUFDOUMsMENBQTBDO0FBQzFDLHdEQUF3RDtBQUN4RCxvQ0FBb0M7QUFDcEMsT0FBTyxDQUFDLFNBQVMsQ0FBQyxDQUFDO0FBRW5CLElBQUksQ0FBQyxhQUFhLEVBQUUsS0FBSyxFQUFDLENBQUMsRUFBQyxFQUFFO0lBQzVCLG9CQUFvQjtJQUVwQixvRUFBb0U7SUFDcEUsaUVBQWlFO0lBQ2pFLG9DQUFvQztJQUNwQyx5QkFBeUI7SUFDekIsOElBQThJO0lBQzlJLDBIQUEwSDtJQUMxSCx3Q0FBd0M7SUFDeEMsdUJBQXVCO0lBRXZCLDRMQUE0TDtJQUM1TCxpQ0FBaUM7SUFDakMsOEJBQThCO0lBQzlCLCtCQUErQjtJQUMvQixnQ0FBZ0M7SUFDaEMsZ0NB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0FBc0M7SUFFdEMsc0NBQXNDO0lBQ3RDLGlCQUFpQjtJQUNqQixrQkFBa0I7SUFDbEIsSUFBSTtJQUVKLHlHQUF5RztJQUN6Ryx3Q0FBd0M7SUFFeEMseUdBQXlHO0lBQ3pHLHdDQUF3QztJQUV4Qyw4RkFBOEY7SUFDOUYsOEJBQThCO0lBQzlCLGtDQUFrQztJQUNsQyxvQkFBb0I7SUFDcEIsd0JBQXdCO0lBQ3hCLElBQUk7SUFFSixDQUFDLENBQUMsSUFBSSxFQUFFLENBQUE7QUFDVixDQUFDLENBQUMsQ0FBQyJ9 \ No newline at end of file diff --git a/build/module/core/SecretKey.d.ts b/build/module/core/SecretKey.d.ts new file mode 100644 index 0000000..a9a9442 --- /dev/null +++ b/build/module/core/SecretKey.d.ts @@ -0,0 +1,10 @@ +import { IAcc } from './types/common'; +export default class SecretKey { + generateMnemonic(): string; + genarateKeyPair(mnemonic: string): IAcc; + recoveryKeyPair(privateKey: string): IAcc; + verifyBech32String(accAddress: string): any; + getBech32PubKey(publicKey: any): any; + test(): void; + getAddress(publicKey: Uint8Array): any; +} diff --git a/build/module/core/SecretKey.js b/build/module/core/SecretKey.js new file mode 100644 index 0000000..3ab7789 --- /dev/null +++ b/build/module/core/SecretKey.js @@ -0,0 +1,61 @@ +import { generateMnemonic } from 'bip39'; +require('qosKeys'); +export default class SecretKey { + generateMnemonic() { + // 商 256,生成24个助记单词, 商 128,生成12个助记单词 + const mnemonic = generateMnemonic(128); + return mnemonic; + } + genarateKeyPair(mnemonic) { + // 根据助记词得到账户信息 + // @ts-ignore + const [hexprikey, pubkey, accaddr, prikeyBz, pubkeyBz, err] = global.qosKeys.DeriveQOSKey(mnemonic); + return { + address: accaddr, + keyPair: { + hexPrivateKey: hexprikey, + privateKey: prikeyBz, + pubKey: pubkeyBz + } + }; + } + recoveryKeyPair(privateKey) { + // 根据私钥得到账户信息 + // @ts-ignore + const [hexprikey, pubkey, accaddr, prikeyBz, pubkeyBz, err] = global.qosKeys.RecoverFromPrivateKey(privateKey); + return { + address: accaddr, + keyPair: { + hexPrivateKey: hexprikey, + privateKey: prikeyBz, + pubKey: pubkeyBz + } + }; + } + verifyBech32String(accAddress) { + const isValidate = global.qosKeys.VerifyBech32String(accAddress); + return isValidate; + } + getBech32PubKey(publicKey) { + const [bech32pubkey, err2] = global.qosKeys.Bech32ifyQOSAccPubKey(publicKey); + if (err2 != null) { + throw err2; + } + return bech32pubkey; + } + test() { + // return keyPair + } + getAddress(publicKey) { + const [addrBech32, err] = global.qosKeys.Bech32ifyQOSAccAddressFromPubKey(publicKey); + if (err != null) { + throw err; + } + return addrBech32; + // const pkAarry = getHash256(publicKey); + // const nw = bech32.toWords(Buffer.from(pkAarry.slice(0, 20))); + // const addr = bech32.encode('qosacc', nw); + // return addr; + } +} +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiU2VjcmV0S2V5LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2NvcmUvU2VjcmV0S2V5LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLE9BQU8sQ0FBQztBQUV6QyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUM7QUFFbkIsTUFBTSxDQUFDLE9BQU8sT0FBTyxTQUFTO0lBQ3JCLGdCQUFnQjtRQUNyQixtQ0FBbUM7UUFDbkMsTUFBTSxRQUFRLEdBQUcsZ0JBQWdCLENBQUMsR0FBRyxDQUFDLENBQUM7UUFDdkMsT0FBTyxRQUFRLENBQUM7SUFDbEIsQ0FBQztJQUVNLGVBQWUsQ0FBQyxRQUFnQjtRQUNyQyxjQUFjO1FBQ2QsYUFBYTtRQUNiLE1BQU0sQ0FBQyxTQUFTLEVBQUUsTUFBTSxFQUFFLE9BQU8sRUFBRSxRQUFRLEVBQUUsUUFBUSxFQUFFLEdBQUcsQ0FBQ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LENBQUM7U0FDWjtRQUNELE9BQU8sWUFBWSxDQUFBO0lBQ3JCLENBQUM7SUFDTSxJQUFJO1FBRVQsaUJBQWlCO0lBQ25CLENBQUM7SUFFTSxVQUFVLENBQUMsU0FBcUI7UUFDckMsTUFBTSxDQUFDLFVBQVUsRUFBRSxHQUFHLENBQUMsR0FBSSxNQUFjLENBQUMsT0FBTyxDQUFDLGdDQUFnQyxDQUFDLFNBQVMsQ0FBQyxDQUFDO1FBQzlGLElBQUksR0FBRyxJQUFJLElBQUksRUFBRTtZQUNmLE1BQU0sR0FBRyxDQUFDO1NBQ1g7UUFDRCxPQUFPLFVBQVUsQ0FBQTtRQUNqQix5Q0FBeUM7UUFDekMsZ0VBQWdFO1FBQ2hFLDRDQUE0QztRQUM1QyxlQUFlO0lBQ2pCLENBQUM7Q0FDRiJ9 \ No newline at end of file diff --git a/build/module/core/Tx.d.ts b/build/module/core/Tx.d.ts new file mode 100644 index 0000000..50c64d2 --- /dev/null +++ b/build/module/core/Tx.d.ts @@ -0,0 +1,7 @@ +import QOSRpc from './QOSRpc'; +declare class Tx { + rpc: QOSRpc; + constructor(controller: QOSRpc); + sendTx(): Promise>; +} +export default Tx; diff --git a/build/module/core/Tx.js b/build/module/core/Tx.js new file mode 100644 index 0000000..186a96a --- /dev/null +++ b/build/module/core/Tx.js @@ -0,0 +1,16 @@ +class Tx { + constructor(controller) { + this.rpc = controller; + } + async sendTx() { + const res = await this.rpc.request.post('/bank/accounts/qosacc12z5jn6c3qu3j2zy80ydwjm8pjwu3h8tqk3cwya/transfers', { + 'base': { + 'from': 'qosacc1kcj2ktlvqgdrznprtf5ypgkewm2dh5sc3enx5l' + }, + 'qos': '1000' + }); + return res; + } +} +export default Tx; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiVHguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvY29yZS9UeC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxNQUFNLEVBQUU7SUFFTixZQUFZLFVBQWtCO1FBQzVCLElBQUksQ0FBQyxHQUFHLEdBQUcsVUFBVSxDQUFDO0lBQ3hCLENBQUM7SUFDTSxLQUFLLENBQUMsTUFBTTtRQUNqQixNQUFNLEdBQUcsR0FBRyxNQUFNLElBQUksQ0FBQyxHQUFHLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyx3RUFBd0UsRUFDOUc7WUFDRSxNQUFNLEVBQUU7Z0JBQ04sTUFBTSxFQUFFLCtDQUErQzthQUN4RDtZQUNELEtBQUssRUFBRSxNQUFNO1NBQ2QsQ0FBQyxDQUFBO1FBQ0osT0FBTyxHQUFHLENBQUE7SUFDWixDQUFDO0NBQ0Y7QUFFRCxlQUFlLEVBQUUsQ0FBQSJ9 \ No newline at end of file diff --git a/build/module/core/Txs/Approve.d.ts b/build/module/core/Txs/Approve.d.ts new file mode 100644 index 0000000..a6cb6f1 --- /dev/null +++ b/build/module/core/Txs/Approve.d.ts @@ -0,0 +1,17 @@ +import Account from '../Account'; +import QOSRpc from '../QOSRpc'; +import { IQSC } from '../types/common'; +import { IBaseInput } from '../types/IBaseInput'; +import Tx from './Tx'; +export interface IApproveInput extends IBaseInput { + qos: string; + qscs?: IQSC[]; +} +export default class Approve extends Tx { + constructor(rpc: QOSRpc, account: Account); + execApproveTx(address: string, data: IApproveInput): Promise>; + execCancelApproveTx(address: string, data: IApproveInput): Promise>; + execIncreaseApproveTx(address: string, data: IApproveInput): Promise>; + execDecreaseApproveTx(address: string, data: IApproveInput): Promise>; + execUseApproveTx(address: string, data: IApproveInput): Promise>; +} diff --git a/build/module/core/Txs/Approve.js b/build/module/core/Txs/Approve.js new file mode 100644 index 0000000..ee8a96d --- /dev/null +++ b/build/module/core/Txs/Approve.js @@ -0,0 +1,86 @@ +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +import { after } from '../common/decorator'; +import { componentSignData } from '../common/sign'; +import Tx from './Tx'; +async function sendTx(target, result) { + const res = await target.sendTx({ tx: result }); + return res; +} +export default class Approve extends Tx { + constructor(rpc, account) { + super(rpc, account); + } + async execApproveTx(address, data) { + const res = await this.rpc.request({ + method: 'POST', + url: `/approve/approves/${address}/create_approves`, + data + }); + return res; + } + async execCancelApproveTx(address, data) { + const res = await this.rpc.request({ + method: 'POST', + url: `/approve/approves/${address}/cancel_approves`, + data + }); + return res; + } + async execIncreaseApproveTx(address, data) { + const res = await this.rpc.request({ + method: 'POST', + url: `/approve/approves/${address}/increase_approves`, + data + }); + return res; + } + async execDecreaseApproveTx(address, data) { + const res = await this.rpc.request({ + method: 'POST', + url: `/approve/approves/${address}/decrease_approves`, + data + }); + return res; + } + async execUseApproveTx(address, data) { + const res = await this.rpc.request({ + method: 'POST', + url: `/approve/approves/${address}/use_approves`, + data + }); + return res; + } +} +__decorate([ + after(componentSignData, sendTx), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String, Object]), + __metadata("design:returntype", Promise) +], Approve.prototype, "execApproveTx", null); +__decorate([ + after(componentSignData, sendTx), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String, Object]), + __metadata("design:returntype", Promise) +], Approve.prototype, "execCancelApproveTx", null); +__decorate([ + after(componentSignData, sendTx), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String, Object]), + __metadata("design:returntype", Promise) +], Approve.prototype, "execDecreaseApproveTx", null); +__decorate([ + after(componentSignData, sendTx), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String, Object]), + __metadata("design:returntype", Promise) +], Approve.prototype, "execUseApproveTx", null); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQXBwcm92ZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9jb3JlL1R4cy9BcHByb3ZlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7OztBQUNBLE9BQU8sRUFBRSxLQUFLLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUM1QyxPQUFPLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSxnQkFBZ0IsQ0FBQztBQUluRCxPQUFPLEVBQUUsTUFBTSxNQUFNLENBQUM7QUFPdEIsS0FBSyxVQUFVLE1BQU0sQ0FBQyxNQUFlLEVBQUUsTUFBVztJQUM5QyxNQUFNLEdBQUcsR0FBRyxNQUFNLE1BQU0sQ0FBQyxNQUFNLENBQUMsRUFBRSxFQUFFLEVBQUUsTUFBTSxFQUFFLENBQUMsQ0FBQTtJQUMvQyxPQUFPLEdBQUcsQ0FBQTtBQUNkLENBQUM7QUFFRCxNQUFNLENBQUMsT0FBTyxPQUFPLE9BQVEsU0FBUSxFQUFFO0lBQ25DLFlBQVksR0FBVyxFQUFFLE9BQWdCO1FBQ3ZDLEtBQUssQ0FBQyxHQUFHLEVBQUUsT0FBTyxDQUFDLENBQUE7SUFDckIsQ0FBQztJQUdJLEtBQUssQ0FBQyxhQUFhLENBQUMsT0FBZSxFQUFFLElBQW1CO1FBQzdELE1BQU0sR0FBRyxHQUFHLE1BQU0sSUFBSSxDQUFDLEdBQUcsQ0FBQyxPQUFPLENBQUM7WUFDakMsTUFBTSxFQUFFLE1BQU07WUFDZCxHQUFHLEVBQUUscUJBQXFCLE9BQU8sa0JBQWtCO1lBQ25ELElBQUk7U0FDTCxDQUFDLENBQUE7UUFDR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UJBQXFCLE9BQU8sZUFBZTtZQUNoRCxJQUFJO1NBQ0wsQ0FBQyxDQUFBO1FBQ0YsT0FBTyxHQUFHLENBQUE7SUFDWixDQUFDO0NBQ0Y7QUEvQ0M7SUFEQyxLQUFLLENBQUMsaUJBQWlCLEVBQUUsTUFBTSxDQUFDOzs7OzRDQVFoQztBQUdEO0lBREMsS0FBSyxDQUFDLGlCQUFpQixFQUFFLE1BQU0sQ0FBQzs7OztrREFRaEM7QUFZRDtJQURDLEtBQUssQ0FBQyxpQkFBaUIsRUFBRSxNQUFNLENBQUM7Ozs7b0RBUWhDO0FBR0Q7SUFEQyxLQUFLLENBQUMsaUJBQWlCLEVBQUUsTUFBTSxDQUFDOzs7OytDQVFoQyJ9 \ No newline at end of file diff --git a/build/module/core/Txs/Bank.d.ts b/build/module/core/Txs/Bank.d.ts new file mode 100644 index 0000000..a35b183 --- /dev/null +++ b/build/module/core/Txs/Bank.d.ts @@ -0,0 +1,15 @@ +import Account from '../Account'; +import QOSRpc from '../QOSRpc'; +import { IQSC } from '../types/common'; +import { IBaseInput } from '../types/IBaseInput'; +import Tx from './Tx'; +export interface ITransferInput extends IBaseInput { + qos: string; + qscs?: IQSC[]; +} +export default class Bank extends Tx { + constructor(rpc: QOSRpc, account: Account); + execTransferTx(address: string, data: ITransferInput): Promise>; + execCheckTx(data: ITransferInput): Promise>; + execQueryAccount(accountAddress: string): Promise>; +} diff --git a/build/module/core/Txs/Bank.js b/build/module/core/Txs/Bank.js new file mode 100644 index 0000000..eebb23e --- /dev/null +++ b/build/module/core/Txs/Bank.js @@ -0,0 +1,48 @@ +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +import { after } from '../common/decorator'; +import { componentSignData } from '../common/sign'; +import Tx from './Tx'; +async function sendTx(target, result) { + const res = await target.sendTx({ tx: result }); + return res; +} +export default class Bank extends Tx { + constructor(rpc, account) { + super(rpc, account); + } + async execTransferTx(address, data) { + const res = await this.rpc.post(`/bank/accounts/${address}/transfers`, data); + return res; + } + async execCheckTx(data) { + // const res = await this.rpc.request({ + // method: 'POST', + const res = await this.rpc.post('/bank/accounts/checks', data); + return res; + } + async execQueryAccount(accountAddress) { + const res = await this.rpc.get(`/accounts/${accountAddress}`); + return res; + } +} +__decorate([ + after(componentSignData, sendTx), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String, Object]), + __metadata("design:returntype", Promise) +], Bank.prototype, "execTransferTx", null); +__decorate([ + after(componentSignData, sendTx), + __metadata("design:type", Function), + __metadata("design:paramtypes", [Object]), + __metadata("design:returntype", Promise) +], Bank.prototype, "execCheckTx", null); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQmFuay5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9jb3JlL1R4cy9CYW5rLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7OztBQUNBLE9BQU8sRUFBRSxLQUFLLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUM1QyxPQUFPLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSxnQkFBZ0IsQ0FBQztBQUluRCxPQUFPLEVBQUUsTUFBTSxNQUFNLENBQUM7QUFPdEIsS0FBSyxVQUFVLE1BQU0sQ0FBQyxNQUFZLEVBQUUsTUFBVztJQUM3QyxNQUFNLEdBQUcsR0FBRyxNQ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TUFBTSxDQUFDOzs7O3VDQVNoQyJ9 \ No newline at end of file diff --git a/build/module/core/Txs/Delegation.d.ts b/build/module/core/Txs/Delegation.d.ts new file mode 100644 index 0000000..7602283 --- /dev/null +++ b/build/module/core/Txs/Delegation.d.ts @@ -0,0 +1,25 @@ +import Account from '../Account'; +import QOSRpc from '../QOSRpc'; +import { IBaseInput } from '../types/IBaseInput'; +import Tx from './Tx'; +export interface ICreateDelegationInput extends IBaseInput { + amount: string; + is_compound?: boolean; +} +export interface IModifyDelegationInput extends IBaseInput { + is_compound: boolean; +} +export interface IUnbondDelegationInput extends IBaseInput { + unbond_amount?: string; + unbond_all?: boolean; +} +export default class Delegation extends Tx { + constructor(rpc: QOSRpc, account: Account); + execCreateDelegationTx(validatorAddress: string, data: ICreateDelegationInput): Promise>; + execModifyDelegationTx(validatorAddress: string, data: IModifyDelegationInput): Promise>; + execUnbondDelegationTx(validatorAddress: string, data: IUnbondDelegationInput): Promise>; + execQueryDelegationAll(delegatorAddress: string): Promise>; + execQueryDelegationOne(delegatorAddress: string, validatorAddress: string): Promise>; + execQueryValidatorAll(): Promise>; + execQueryValidatorOne(validatorAddress: string): Promise>; +} diff --git a/build/module/core/Txs/Delegation.js b/build/module/core/Txs/Delegation.js new file mode 100644 index 0000000..f65558f --- /dev/null +++ b/build/module/core/Txs/Delegation.js @@ -0,0 +1,68 @@ +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +import { after } from '../common/decorator'; +import { componentSignData } from '../common/sign'; +import Tx from './Tx'; +async function sendTx(target, result) { + const res = await target.sendTx({ tx: result }); + return res; +} +export default class Delegation extends Tx { + constructor(rpc, account) { + super(rpc, account); + } + async execCreateDelegationTx(validatorAddress, data) { + const res = await this.rpc.post(`/stake/delegators/${validatorAddress}/delegations`, data); + return res; + } + async execModifyDelegationTx(validatorAddress, data) { + const res = await this.rpc.post(`/stake/delegators/${validatorAddress}/modify_delegations`, data); + return res; + } + async execUnbondDelegationTx(validatorAddress, data) { + const res = await this.rpc.post(`/stake/delegators/${validatorAddress}/unbond_delegations`, data); + return res; + } + async execQueryDelegationAll(delegatorAddress) { + const res = await this.rpc.get(`/stake/delegators/${delegatorAddress}/delegations`); + return res; + } + async execQueryDelegationOne(delegatorAddress, validatorAddress) { + const res = await this.rpc.get(`/stake/delegators/${delegatorAddress}/validators/${validatorAddress}`); + return res; + } + async execQueryValidatorAll() { + const res = await this.rpc.get('/stake/validators'); + return res; + } + async execQueryValidatorOne(validatorAddress) { + const res = await this.rpc.get(`/stake/validators/${validatorAddress}`); + return res; + } +} +__decorate([ + after(componentSignData, sendTx), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String, Object]), + __metadata("design:returntype", Promise) +], Delegation.prototype, "execCreateDelegationTx", null); +__decorate([ + after(componentSignData, sendTx), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String, Object]), + __metadata("design:returntype", Promise) +], Delegation.prototype, "execModifyDelegationTx", null); +__decorate([ + after(componentSignData, sendTx), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String, Object]), + __metadata("design:returntype", Promise) +], Delegation.prototype, "execUnbondDelegationTx", null); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRGVsZWdhdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9jb3JlL1R4cy9EZWxlZ2F0aW9uLnRz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M7Q0FJRjtBQXhEQztJQURDLEtBQUssQ0FBQyxpQkFBaUIsRUFBRSxNQUFNLENBQUM7Ozs7d0RBT2hDO0FBR0Q7SUFEQyxLQUFLLENBQUMsaUJBQWlCLEVBQUUsTUFBTSxDQUFDOzs7O3dEQU9oQztBQUdEO0lBREMsS0FBSyxDQUFDLGlCQUFpQixFQUFFLE1BQU0sQ0FBQzs7Ozt3REFPaEMifQ== \ No newline at end of file diff --git a/build/module/core/Txs/Tx.d.ts b/build/module/core/Txs/Tx.d.ts new file mode 100644 index 0000000..45bad5b --- /dev/null +++ b/build/module/core/Txs/Tx.d.ts @@ -0,0 +1,11 @@ +import QOSRpc from '../..'; +import Account from '../Account'; +export default class Tx { + rpc: QOSRpc; + account: Account; + constructor(rpc: QOSRpc, account: Account); + sendTx({ tx, mode }: { + tx: string; + mode?: 'block' | 'sync' | 'async'; + }): Promise>; +} diff --git a/build/module/core/Txs/Tx.js b/build/module/core/Txs/Tx.js new file mode 100644 index 0000000..c2006c9 --- /dev/null +++ b/build/module/core/Txs/Tx.js @@ -0,0 +1,15 @@ +export default class Tx { + constructor(rpc, account) { + this.rpc = rpc; + this.account = account; + } + async sendTx({ tx, mode = 'block' }) { + const res = await this.rpc.request({ + method: 'POST', + url: '/txs', + data: { tx, mode } + }).catch(err => console.log(err)); + return res; + } +} +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiVHguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvY29yZS9UeHMvVHgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBR0EsTUFBTSxDQUFDLE9BQU8sT0FBTyxFQUFFO0lBR3JCLFlBQVksR0FBVyxFQUFFLE9BQWdCO1FBQ3ZDLElBQUksQ0FBQyxHQUFHLEdBQUcsR0FBRyxDQUFDO1FBQ2YsSUFBSSxDQUFDLE9BQU8sR0FBRyxPQUFPLENBQUM7SUFDekIsQ0FBQztJQUVNLEtBQUssQ0FBQyxNQUFNLENBQUMsRUFBRSxFQUFFLEVBQUUsSUFBSSxHQUFHLE9BQU8sRUFBb0Q7UUFDMUYsTUFBTSxHQUFHLEdBQUcsTUFBTyxJQUFJLENBQUMsR0FBRyxDQUFDLE9BQU8sQ0FBQztZQUNsQyxNQUFNLEVBQUUsTUFBTTtZQUNkLEdBQUcsRUFBRSxNQUFNO1lBQ1gsSUFBSSxFQUFFLEVBQUUsRUFBRSxFQUFFLElBQUksRUFBRTtTQUNuQixDQUFDLENBQUMsS0FBSyxDQUFDLEdBQUcsQ0FBQyxFQUFFLENBQUMsT0FBTyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFBO1FBQ2pDLE9BQU8sR0FBRyxDQUFBO0lBQ1osQ0FBQztDQUNGIn0= \ No newline at end of file diff --git a/build/module/core/common/decorator.d.ts b/build/module/core/common/decorator.d.ts new file mode 100644 index 0000000..ba5c036 --- /dev/null +++ b/build/module/core/common/decorator.d.ts @@ -0,0 +1 @@ +export declare function after(...args: any[]): (_target: any, _key: any, descriptor: any) => any; diff --git a/build/module/core/common/decorator.js b/build/module/core/common/decorator.js new file mode 100644 index 0000000..aec5517 --- /dev/null +++ b/build/module/core/common/decorator.js @@ -0,0 +1,19 @@ +export function after(...args) { + return (_target, _key, descriptor) => { + // 获取value,其实就是原函数 + const oldValue = descriptor.value; + // 将value重新赋值一个函数 + descriptor.value = async function () { + // tslint:disable-next-line: no-console + // 将原本的函数执行一下,apply改变this的指向 + const val = await oldValue.apply(this, arguments); + let result = val; + for (const callback of args) { + result = (await callback(this, result, ...arguments)) || result; + } + return result; + }; + return descriptor; + }; +} +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVjb3JhdG9yLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL2NvcmUvY29tbW9uL2RlY29yYXRvci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxNQUFNLFVBQVUsS0FBSyxDQUFDLEdBQUcsSUFBSTtJQUMzQixPQUFPLENBQUMsT0FBTyxFQUFFLElBQUksRUFBRSxVQUFVLEVBQUUsRUFBRTtRQUNuQyxrQkFBa0I7UUFDbEIsTUFBTSxRQUFRLEdBQUcsVUFBVSxDQUFDLEtBQUssQ0FBQztRQUNsQyxpQkFBaUI7UUFDakIsVUFBVSxDQUFDLEtBQUssR0FBRyxLQUFLO1lBQ3RCLHVDQUF1QztZQUN2Qyw0QkFBNEI7WUFDNUIsTUFBTSxHQUFHLEdBQUcsTUFBTSxRQUFRLENBQUMsS0FBSyxDQUFDLElBQUksRUFBRSxTQUFTLENBQUMsQ0FBQTtZQUNqRCxJQUFJLE1BQU0sR0FBRyxHQUFHLENBQUM7WUFDakIsS0FBSyxNQUFNLFFBQVEsSUFBSSxJQUFJLEVBQUU7Z0JBQzNCLE1BQU0sR0FBRyxDQUFDLE1BQU0sUUFBUSxDQUFDLElBQUksRUFBRSxNQUFNLEVBQUUsR0FBRyxTQUFTLENBQUMsQ0FBQyxJQUFJLE1BQU0sQ0FBQTthQUNoRTtZQUNELE9BQU8sTUFBTSxDQUFDO1FBQ2hCLENBQUMsQ0FBQztRQUVGLE9BQU8sVUFBVSxDQUFDO0lBQ3BCLENBQUMsQ0FBQTtBQUNILENBQUMifQ== \ No newline at end of file diff --git a/build/module/core/common/sign.d.ts b/build/module/core/common/sign.d.ts new file mode 100644 index 0000000..0166e21 --- /dev/null +++ b/build/module/core/common/sign.d.ts @@ -0,0 +1,4 @@ +import Account from '../Account'; +import Tx from '../Txs/Tx'; +export declare function sign(account: Account, data: any): string; +export declare function componentSignData(target: Tx, res: any): Promise; diff --git a/build/module/core/common/sign.js b/build/module/core/common/sign.js new file mode 100644 index 0000000..a88f8f1 --- /dev/null +++ b/build/module/core/common/sign.js @@ -0,0 +1,24 @@ +// import ed25519 from 'supercop.js' +// import nacl from 'tweetnacl'; +require('qosKeys'); +import { encodeBase64 } from '../utils'; +export function sign(account, data) { + // const sig = nacl.sign.detached(decodeBase64(data), account.keypair.privateKey) + // const sig = ed25519.Sign(decodeBase64(data), account.keypair.privateKey); + const sig = global.qosKeys.SignBase64Message(account.keypair.hexPrivateKey, data); + // logger.debug('sig', encodeBase64(sig)) + return encodeBase64(sig); +} +export async function componentSignData(target, res) { + const sig = sign(target.account, res.data.sign_bytes); + const resObj = JSON.parse(res.data.tx); + const pubkeyBase64 = global.qosKeys.EncodeBase64(target.account.pubKeyBz); + resObj.value.sigature[0].signature = sig; + resObj.value.sigature[0].pubkey = { + type: 'tendermint/PubKeyEd25519', + // 'value': 'lDomDLEe+ou01k4FsNLJOdU10rhlpBxVQR+BAwSpUzc=' + value: pubkeyBase64 + }; + return resObj; +} +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2lnbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9jb3JlL2NvbW1vbi9zaWduLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLG9DQUFvQztBQUNwQyxnQ0FBZ0M7QUFDaEMsT0FBTyxDQUFDLFNBQVMsQ0FBQyxDQUFDO0FBR25CLE9BQU8sRUFBRSxZQUFZLEVBQUUsTUFBTSxVQUFVLENBQUM7QUFFeEMsTUFBTSxVQUFVLElBQUksQ0FBQyxPQUFnQixFQUFFLElBQVM7SUFDOUMsaUZBQWlGO0lBQ2pGLDRFQUE0RTtJQUM1RSxNQUFNLEdBQUcsR0FBSSxNQUFjLENBQUMsT0FBTyxDQUFDLGlCQUFpQixDQUFDLE9BQU8sQ0FBQyxPQUFPLENBQUMsYUFBYSxFQUFFLElBQUksQ0FBQyxDQUFDO0lBRTNGLHlDQUF5QztJQUV6QyxPQUFPLFlBQVksQ0FBQyxHQUFHLENBQUMsQ0FBQTtBQUMxQixDQUFDO0FBRUQsTUFBTSxDQUFDLEtBQUssVUFBVSxpQkFBaUIsQ0FBQyxNQUFVLEVBQUUsR0FBUTtJQUMxRCxNQUFNLEdBQUcsR0FBRyxJQUFJLENBQUUsTUFBYyxDQUFDLE9BQU8sRUFBRSxHQUFHLENBQUMsSUFBSSxDQUFDLFVBQVUsQ0FBQyxDQUFBO0lBQzlELE1BQU0sTUFBTSxHQUFHLElBQUksQ0FBQyxLQUFLLENBQUMsR0FBRyxDQUFDLElBQUksQ0FBQyxFQUFFLENBQUMsQ0FBQTtJQUN0QyxNQUFNLFlBQVksR0FBSSxNQUFjLENBQUMsT0FBTyxDQUFDLFlBQVksQ0FBQyxNQUFNLENBQUMsT0FBTyxDQUFDLFFBQVEsQ0FBQyxDQUFBO0lBRWxGLE1BQU0sQ0FBQyxLQUFLLENBQUMsUUFBUSxDQUFDLENBQUMsQ0FBQyxDQUFDLFNBQVMsR0FBRyxHQUFHLENBQUE7SUFDeEMsTUFBTSxDQUFDLEtBQUssQ0FBQyxRQUFRLENBQUMsQ0FBQyxDQUFDLENBQUMsTUFBTSxHQUFHO1FBQ2hDLElBQUksRUFBRSwwQkFBMEI7UUFDaEMsMERBQTBEO1FBQzFELEtBQUssRUFBRSxZQUFZO0tBQ3BCLENBQUE7SUFDRCxPQUFPLE1BQU0sQ0FBQTtBQUNmLENBQUMifQ== \ No newline at end of file diff --git a/build/module/core/types/IBaseInput.d.ts b/build/module/core/types/IBaseInput.d.ts new file mode 100644 index 0000000..e4eedb2 --- /dev/null +++ b/build/module/core/types/IBaseInput.d.ts @@ -0,0 +1,12 @@ +export interface IBase { + from: string; + chain_id?: string; + nonce?: string; + max_gas?: string; + height?: number; + indent?: boolean; + mode?: string; +} +export interface IBaseInput { + base: IBase; +} diff --git a/build/module/core/types/IBaseInput.js b/build/module/core/types/IBaseInput.js new file mode 100644 index 0000000..7f54698 --- /dev/null +++ b/build/module/core/types/IBaseInput.js @@ -0,0 +1 @@ +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSUJhc2VJbnB1dC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9jb3JlL3R5cGVzL0lCYXNlSW5wdXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9 \ No newline at end of file diff --git a/build/module/core/types/common.d.ts b/build/module/core/types/common.d.ts new file mode 100644 index 0000000..298d3d6 --- /dev/null +++ b/build/module/core/types/common.d.ts @@ -0,0 +1,13 @@ +export interface IKeyPair { + privateKey: Uint8Array; + pubKey: Uint8Array; + hexPrivateKey: string; +} +export interface IAcc { + address: string; + keyPair: IKeyPair; +} +export interface IQSC { + coin_name: string; + amount: number; +} diff --git a/build/module/core/types/common.js b/build/module/core/types/common.js new file mode 100644 index 0000000..d94d311 --- /dev/null +++ b/build/module/core/types/common.js @@ -0,0 +1 @@ +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tbW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL2NvcmUvdHlwZXMvY29tbW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiIifQ== \ No newline at end of file diff --git a/build/module/core/utils/index.d.ts b/build/module/core/utils/index.d.ts new file mode 100644 index 0000000..0817a58 --- /dev/null +++ b/build/module/core/utils/index.d.ts @@ -0,0 +1,18 @@ +/// +/** + * 是否合法数据 + * @param value any + */ +export declare function isNotEmpty(value: any): boolean; +export declare function getHash256(input: any): any; +export declare function buf2hex(buffer: any): any; +export declare function stringToBuffer(val: string, encoding?: BufferEncoding): Buffer; +export declare function encodeBase64(val: any): string; +export declare function decodeBase64(val: any): Uint8Array; +export declare function stringToHex(str: string): string; +/** + * 乘法 + * @param arg1 + * @param arg2 + */ +export declare function accMul(arg1: number, arg2: number): number; diff --git a/build/module/core/utils/index.js b/build/module/core/utils/index.js new file mode 100644 index 0000000..b247c34 --- /dev/null +++ b/build/module/core/utils/index.js @@ -0,0 +1,65 @@ +// import { Int64BE } from 'int64-buffer'; +import { decodeBase64 as dcbase64, encodeBase64 as ecbase64 } from 'tweetnacl-util'; +/** + * 是否合法数据 + * @param value any + */ +export function isNotEmpty(value) { + if (value !== undefined && value !== '' && value != null) { + return true; + } + return false; +} +export function getHash256(input) { + const sha256 = require('js-sha256'); + const hash2 = sha256.update(input); + return hash2.array(); +} +// export function Int64ToBuffer(val: number) { +// return new Int64BE(val).toBuffer(); +// } +export function buf2hex(buffer) { + return Array.prototype.map + .call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)) + .join(''); +} +export function stringToBuffer(val, encoding = 'ascii') { + return Buffer.from(val, encoding); +} +export function encodeBase64(val) { + return ecbase64(val); +} +export function decodeBase64(val) { + return dcbase64(val); +} +export function stringToHex(str) { + let val = ''; + // tslint:disable-next-line: no-let + for (let i = 0; i < str.length; i++) { + val += str.charCodeAt(i).toString(16); + } + return val; +} +/** + * 乘法 + * @param arg1 + * @param arg2 + */ +export function accMul(arg1, arg2) { + let m = 0; + const s1 = arg1.toString(); + const s2 = arg2.toString(); + try { + m += s1.split('.')[1].length; + // tslint:disable-next-line: no-empty + } + catch (e) { } + try { + m += s2.split('.')[1].length; + // tslint:disable-next-line: no-empty + } + catch (e) { } + return ((Number(s1.replace('.', '')) * Number(s2.replace('.', ''))) / + Math.pow(10, m)); +} +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvY29yZS91dGlscy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSwwQ0FBMEM7QUFDMUMsT0FBTyxFQUNMLFlBQVksSUFBSSxRQUFRLEVBQ3hCLFlBQVksSUFBSSxRQUFRLEVBQ3pCLE1BQU0sZ0JBQWd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BQyxDQUFDLENBQUMsTUFBTSxDQUFDO1FBQzdCLHFDQUFxQztLQUN0QztJQUFDLE9BQU8sQ0FBQyxFQUFFLEdBQUU7SUFDZCxPQUFPLENBQ0wsQ0FBQyxNQUFNLENBQUMsRUFBRSxDQUFDLE9BQU8sQ0FBQyxHQUFHLEVBQUUsRUFBRSxDQUFDLENBQUMsR0FBRyxNQUFNLENBQUMsRUFBRSxDQUFDLE9BQU8sQ0FBQyxHQUFHLEVBQUUsRUFBRSxDQUFDLENBQUMsQ0FBQztRQUMzRCxJQUFJLENBQUMsR0FBRyxDQUFDLEVBQUUsRUFBRSxDQUFDLENBQUMsQ0FDaEIsQ0FBQztBQUNKLENBQUMifQ== \ No newline at end of file diff --git a/build/module/core/utils/request.d.ts b/build/module/core/utils/request.d.ts new file mode 100644 index 0000000..982d169 --- /dev/null +++ b/build/module/core/utils/request.d.ts @@ -0,0 +1,3 @@ +import { AxiosInstance } from 'axios'; +declare const createAxioRequest: (baseUrl: string) => AxiosInstance; +export default createAxioRequest; diff --git a/build/module/core/utils/request.js b/build/module/core/utils/request.js new file mode 100644 index 0000000..0e61a88 --- /dev/null +++ b/build/module/core/utils/request.js @@ -0,0 +1,59 @@ +import axios from 'axios'; +import { isNotEmpty } from '../utils'; +// tslint:disable-next-line: no-let +let httpRequest; +const createAxioRequest = (baseUrl) => { + if (isNotEmpty(httpRequest)) { + return httpRequest; + } + // 创建axios实例 + const request = axios.create({ + baseURL: baseUrl, + timeout: 200000 // 请求超时时间 + }); + // request拦截器 + request.interceptors.request.use(config => { + return config; + }, error => { + // Do something with request error + Promise.reject(error); + }); + // timeout handler + request.interceptors.response.use(undefined, async function axiosRetryInterceptor(err) { + const config = err.config; + // If config does not exist or the retry option is not set, reject + if (!config || !config.retry) { + return Promise.reject(err); + } + // Set the variable for keeping track of the retry count + // tslint:disable-next-line: no-object-mutation + config.__retryCount = config.__retryCount || 0; + // Check if we've maxed out the total number of retries + if (config.__retryCount >= config.retry) { + // Reject with the error + return Promise.reject(err); + } + // Increase the retry count + // tslint:disable-next-line: no-object-mutation + config.__retryCount += 1; + // Create new promise to handle exponential backoff + const backoff = new Promise(resolve => { + setTimeout(() => { + resolve(); + }, config.retryDelay || 1); + }); + // Return the promise in which recalls axios to retry the request + await backoff; + return axios(config); + }); + // respone拦截器 + request.interceptors.response.use(res => { + return res; + }, error => { + return Promise.reject(error); + }); + httpRequest = request; + return httpRequest; +}; +export default createAxioRequest; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVxdWVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9jb3JlL3V0aWxzL3JlcXVlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUF3QixNQUFNLE9BQU8sQ0FBQztBQUM3QyxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sVUFBVSxDQUFDO0FBRXRDLG1DQUFtQztBQUNuQyxJQUFJLFdBQTJCLENBQUM7QUFFaEMsTUFBTSxpQkFBaUIsR0FBRyxDQUFDLE9BQWUsRUFBRSxFQUFFO0lBQzVDLElBQUksVUFBVSxDQUFDLFdBQVcsQ0FBQyxFQUFFO1FBQzNCLE9BQU8sV0FBVyxDQUFDO0tBQ3BCO0lBQ0QsWUFBWTtJQUNaLE1BQU0sT0FBTyxHQUFHLEtBQUssQ0FBQyxNQUFNLENBQUM7UUFDM0IsT0FBTyxFQUFFLE9BQU87UUFDaEIsT0FBTyxFQUFFLE1BQU0sQ0FBQyxTQUFTO0tBQzFCLENBQUMsQ0FBQztJQUVILGFBQWE7SUFDYixPQUFPLENBQUMsWUFBWSxDQUFDLE9BQU8sQ0FBQyxHQUFHLENBQzlCLE1BQU0sQ0FBQyxFQUFFO1FBQ1AsT0FBTyxNQUFNLENBQUM7SUFDaEIsQ0FBQyxFQUNELEtBQUssQ0FBQyxFQUFFO1FBQ04sa0NBQ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QWlFO1FBQ2pFLE1BQU0sT0FBTyxDQUFDO1FBQ2QsT0FBTyxLQUFLLENBQUMsTUFBTSxDQUFDLENBQUM7SUFDdkIsQ0FBQyxDQUNGLENBQUM7SUFFRixhQUFhO0lBQ2IsT0FBTyxDQUFDLFlBQVksQ0FBQyxRQUFRLENBQUMsR0FBRyxDQUMvQixHQUFHLENBQUMsRUFBRTtRQUNKLE9BQU8sR0FBRyxDQUFDO0lBQ2IsQ0FBQyxFQUNELEtBQUssQ0FBQyxFQUFFO1FBQ04sT0FBTyxPQUFPLENBQUMsTUFBTSxDQUFDLEtBQUssQ0FBQyxDQUFDO0lBQy9CLENBQUMsQ0FDRixDQUFDO0lBRUYsV0FBVyxHQUFHLE9BQU8sQ0FBQztJQUN0QixPQUFPLFdBQVcsQ0FBQztBQUNyQixDQUFDLENBQUM7QUFFRixlQUFlLGlCQUFpQixDQUFDIn0= \ No newline at end of file diff --git a/build/module/index.d.ts b/build/module/index.d.ts new file mode 100644 index 0000000..33b2a42 --- /dev/null +++ b/build/module/index.d.ts @@ -0,0 +1,2 @@ +import QOSRpc from './core/QOSRpc'; +export default QOSRpc; diff --git a/build/module/index.js b/build/module/index.js new file mode 100644 index 0000000..6fdf896 --- /dev/null +++ b/build/module/index.js @@ -0,0 +1,3 @@ +import QOSRpc from './core/QOSRpc'; +export default QOSRpc; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxNQUFNLE1BQU0sZUFBZSxDQUFBO0FBRWxDLGVBQWUsTUFBTSxDQUFBIn0= \ No newline at end of file diff --git a/src/core/Account.ts b/src/core/Account.ts index dd9d675..7d3d795 100644 --- a/src/core/Account.ts +++ b/src/core/Account.ts @@ -2,9 +2,7 @@ import QOSRpc from './QOSRpc'; import Approve, { IApproveInput } from './Txs/Approve'; import Bank, { ITransferInput } from './Txs/Bank'; import Delegation, { ICreateDelegationInput, IModifyDelegationInput, IUnbondDelegationInput} from './Txs/Delegation'; -import { IKeyPair } from './types/common'; -import { encodeBase64 } from './utils'; -import logger from './utils/log'; +import { IAcc, IKeyPair } from './types/common'; // import { ITransferInput } from './' class Account { @@ -14,26 +12,27 @@ class Account { public mnemonic: string; public keypair: IKeyPair; public address: string; - public pubKey: string; + // public pubKey: Uint8Array; public privateKey: string; - public bech32pubkey: string; + public privateKeyBz: Uint8Array; + public pubKeyBz: Uint8Array; - constructor(controller: QOSRpc, keyPair?: IKeyPair, mnemonic?: string) { + constructor(controller: QOSRpc, Acc?: IAcc, mnemonic?: string) { this.rpc = controller; - if (keyPair) { + if (Acc) { this.mnemonic = mnemonic; - this.keypair = keyPair; - this.address = this.rpc.key.getAddress(keyPair.publicKey); - this.pubKey = encodeBase64(keyPair.publicKey); - this.privateKey = encodeBase64(keyPair.privateKey); - this.bech32pubkey = keyPair.bech32pubkey; + this.keypair = Acc.keyPair; + this.privateKey = Acc.keyPair.hexPrivateKey; + // this.pubKey = Acc.keyPair.pubKey; + this.address = Acc.address; + this.privateKeyBz = Acc.keyPair.privateKey; + this.pubKeyBz = Acc.keyPair.pubKey; } } public async sendTransferTx(toAddress: string, data: ITransferInput) { const tx = new Bank(this.rpc, this); - const res = await tx.execTransferTx(toAddress, data); - logger.debug('transfer result', res); + const res = await tx.execTransferTx(toAddress, data); return res; } @@ -103,6 +102,12 @@ class Account { return res } + public async queryValidatorAll() { + const tx = new Delegation(this.rpc, this); + const res = await tx.execQueryValidatorAll() + return res + } + public async queryValidatorOne(validatorAddress: string) { const tx = new Delegation(this.rpc, this); const res = await tx.execQueryValidatorOne(validatorAddress) diff --git a/src/core/QOSRpc.spec.ts b/src/core/QOSRpc.spec.ts index 65d9b97..0ca6719 100644 --- a/src/core/QOSRpc.spec.ts +++ b/src/core/QOSRpc.spec.ts @@ -1,114 +1,123 @@ import test from 'ava'; // import nacl from 'tweetnacl'; -import QOSRpc from './QOSRpc'; +// import QOSRpc from './QOSRpc'; // import { IApproveInput } from './Txs/Approve'; // import { ITransferInput } from './Txs/Bank'; // import { IModifyDelegationInput, IUnbondDelegationInput } from './Txs/Delegation'; // import { IBase } from './types/IBaseInput'; -import { encodeBase64 } from './utils'; +// import { encodeBase64 } from './utils'; // import { decodeBase64, encodeBase64 } from './utils'; -import logger from './utils/log'; +// import logger from './utils/log'; +require('qosKeys'); test('qosrpc test', async t => { - logger.debug('1') - - const rpc = new QOSRpc({ baseUrl: 'http://47.100.168.251:9876' }) + // logger.debug('1') + // const rpc = new QOSRpc({ baseUrl: 'http://47.100.168.251:9876' }) + // const rpc = new QOSRpc({ baseUrl: 'http://47.98.253.9:9876' }) // const Mn = rpc.generateMnemonic() // logger.debug('Mn', Mn) // const account = rpc.recoveryAccountByPrivateKey('0mvLfssOE8FN4m2xuzlw1wfC8AKEigZyHyQwQLag9RDSs8G8VniIEnJSmlZWNGDZsR6jBq5c/NY5xcWlUr0J3w==') - const account = rpc.importAccount('violin discover song model crawl distance method guess twenty silly chaos skirt convince hero oxygen cabin palm tomato wing dolphin chief clock cradle tackle') + // const account = rpc.importAccount('giant tackle detail dignity catalog broccoli lady harbor dad mosquito right answer') // const account = rpc.importAccount(Mn) - // logger.debug(account.address) - logger.debug('keyPair.publicKey', (account.keypair.publicKey).join(',')) - logger.debug('keyPair.publicKey encodeBase64', encodeBase64(account.keypair.publicKey)) - logger.debug('keyPair.secretKey', (account.keypair.privateKey).join(',')) - logger.debug('keyPair.secretKey encodeBase64', encodeBase64(account.keypair.privateKey)) - - logger.debug('keyPair.bech32pubkey', account.keypair.bech32pubkey) - logger.debug(account.pubKey) + // console.log(account) + + // const [hexprikey, pubkey, accaddr, prikeyBz, pubkeyBz, err] = (global as any).qosKeys.DeriveQOSKey('giant tackle detail dignity catalog broccoli lady harbor dad mosquito right answer'); + // console.log('----', hexprikey) + // console.log('----', pubkey) + // console.log('----', accaddr) + // console.log('----', prikeyBz) + // console.log('----', pubkeyBz) + // console.log(err) + // logger.debug('keyPair.publicKey', (account.keypair.publicKey).join(',')) + // logger.debug('keyPair.publicKey encodeBase64', encodeBase64(account.keypair.publicKey)) + // logger.debug('keyPair.secretKey', (account.keypair.privateKey).join(',')) + // logger.debug('keyPair.secretKey encodeBase64', encodeBase64(account.keypair.privateKey)) + // logger.debug('keyPair.bech32pubkey', account.keypair.bech32pubkey) + // logger.debug(account.pubKey) // try { - // const res = await rpc.tx.sendTx() - // logger.debug(JSON.stringify(res.data)) - - // const myBase: IBase = { - // from: account.address, - // chain_id: 'aquarius-2001', - // max_gas: '200000', - // } - - // const obj: ITransferInput = { - // qos: '1111', - // base: myBase, - // } - // const res00 = await account.sendTransferTx('qosacc18j9ncemyh0jex3k2yu3s6zh53azfsgxav7t3wq', obj) - // logger.debug('Transfer result', res00) - - // const del: ICreateDelegationInput= { - // amount: '1111', - // base: myBase, - // } - // const res01 = await account.sendCreateDelegateTx('qosval19hrl38w5lm6sklw2hzrzrjtsxudpy8hyfaea3e', del) - // // logger.debug('Create Delegation result', res01) - // logger.debug('Create Delegation result:', res01.status, ', hash:', res01.data.hash) - - // const mod: IModifyDelegationInput= { - // is_compound: true, - // base: myBase, - // } - // const res02 = await account.sendModifyDelegationTx('qosval19hrl38w5lm6sklw2hzrzrjtsxudpy8hyfaea3e', mod) - // logger.debug('Modify Delegation result', res02) - // logger.debug('Modify Delegation result:', res02.status, ', hash:', res02.data.hash) - - // const unbond: IUnbondDelegationInput= { - // unbond_amount: '1111', - // base: myBase, - // } - // const res03 = await account.sendUnbondDelegationTx('qosval19hrl38w5lm6sklw2hzrzrjtsxudpy8hyfaea3e', unbond) - // logger.debug('unbond Delegation result', res03) - // logger.debug('Unbond Delegation result:', res03.status, ', hash:', res03.data.hash) - - // const unbond1: IUnbondDelegationInput= { - // unbond_all: true, - // base: myBase, - // } - // const res04 = await account.sendUnbondDelegationTx('qosval19hrl38w5lm6sklw2hzrzrjtsxudpy8hyfaea3e', unbond1) - // logger.debug('Unbond all Delegation result', res04) - // logger.debug('Unbond all Delegation result:', res04.status, ', hash:', res04.data.hash) - - // ------test query------ - const res05 = await account.queryDelagationAll(account.address) - logger.debug('Query all Delegation result data :', res05.data) - logger.debug('Query all Delegation result status :', res05.status) - - const res06 = await account.queryDelagationOne(account.address, 'qosval19hrl38w5lm6sklw2hzrzrjtsxudpy8hyfaea3e') - logger.debug('Query one Delegation result data :', res06.data) - logger.debug('Query one Delegation result status :', res06.status) - - const res07 = await account.queryValidatorOne('qosval19hrl38w5lm6sklw2hzrzrjtsxudpy8hyfaea3e') - logger.debug('Query one Validator result data :', res07.data) - logger.debug('Query one Validator result status :', res07.status) - - const res08 = await account.queryAccount(account.address) - logger.debug('Query account result data :', res08.data) - logger.debug('Query account result status :', res08.status) - // const res01 = await account.sendCheckTx(obj) - // logger.debug('check result', res01) - - // const approveObj: IApproveInput = { - // qos: '1000', - // base: myBase, - // } - - // const res10 = await account.sendApproveTx('qosacc12z5jn6c3qu3j2zy80ydwjm8pjwu3h8tqk3cwya', approveObj) - // logger.debug('Approve result', res10) - - // const res11 = await account.sendApproveTx('qosacc12z5jn6c3qu3j2zy80ydwjm8pjwu3h8tqk3cwya', approveObj) - // logger.debug('Approve result', res11) - - // const sig = nacl.sign.detached(decodeBase64(res.data.signBytes), account.keypair.secretKey) - // logger.debug(sig.join(',')) - // logger.debug(encodeBase64(sig)) + // const res = await rpc.tx.sendTx() + // logger.debug(JSON.stringify(res.data)) + + // const myBase: IBase = { + // from: account.address, + // chain_id: 'qos-test', + // max_gas: '200000', + // } + + // const obj: ITransferInput = { + // qos: '1000', + // base: myBase, + // } + // await account.sendTransferTx('qosacc1edth0vln3dch80c08adt0pas4vqxnr2u3yf04n', obj) + // logger.debug('Transfer result', res00) + + // const del: ICreateDelegationInput= { + // amount: '1111', + // base: myBase, + // } + // const res01 = await account.sendCreateDelegateTx('qosval19hrl38w5lm6sklw2hzrzrjtsxudpy8hyfaea3e', del) + // // logger.debug('Create Delegation result', res01) + // logger.debug('Create Delegation result:', res01.status, ', hash:', res01.data.hash) + + // const mod: IModifyDelegationInput= { + // is_compound: true, + // base: myBase, + // } + // const res02 = await account.sendModifyDelegationTx('qosval19hrl38w5lm6sklw2hzrzrjtsxudpy8hyfaea3e', mod) + // logger.debug('Modify Delegation result', res02) + // logger.debug('Modify Delegation result:', res02.status, ', hash:', res02.data.hash) + + // const unbond: IUnbondDelegationInput= { + // unbond_amount: '1111', + // base: myBase, + // } + // const res03 = await account.sendUnbondDelegationTx('qosval19hrl38w5lm6sklw2hzrzrjtsxudpy8hyfaea3e', unbond) + // logger.debug('unbond Delegation result', res03) + // logger.debug('Unbond Delegation result:', res03.status, ', hash:', res03.data.hash) + + // const unbond1: IUnbondDelegationInput= { + // unbond_all: true, + // base: myBase, + // } + // const res04 = await account.sendUnbondDelegationTx('qosval19hrl38w5lm6sklw2hzrzrjtsxudpy8hyfaea3e', unbond1) + // logger.debug('Unbond all Delegation result', res04) + // logger.debug('Unbond all Delegation result:', res04.status, ', hash:', res04.data.hash) + + // ------test query------ + // const res05 = await account.queryDelagationAll(account.address) + // logger.debug('Query all Delegation result data :', res05.data) + // logger.debug('Query all Delegation result status :', res05.status) + + // const res06 = await account.queryDelagationOne(account.address, 'qosval19hrl38w5lm6sklw2hzrzrjtsxudpy8hyfaea3e') + // logger.debug('Query one Delegation result data :', res06.data) + // logger.debug('Query one Delegation result status :', res06.status) + + // const res07 = await account.queryValidatorOne('qosval19hrl38w5lm6sklw2hzrzrjtsxudpy8hyfaea3e') + // logger.debug('Query one Validator result data :', res07.data) + // logger.debug('Query one Validator result status :', res07.status) + + // const res08 = await account.queryAccount(account.address) + + + + // const res01 = await account.sendCheckTx(obj) + // logger.debug('check result', res01) + + // const approveObj: IApproveInput = { + // qos: '1000', + // base: myBase, + // } + + // const res10 = await account.sendApproveTx('qosacc12z5jn6c3qu3j2zy80ydwjm8pjwu3h8tqk3cwya', approveObj) + // logger.debug('Approve result', res10) + + // const res11 = await account.sendApproveTx('qosacc12z5jn6c3qu3j2zy80ydwjm8pjwu3h8tqk3cwya', approveObj) + // logger.debug('Approve result', res11) + + // const sig = nacl.sign.detached(decodeBase64(res.data.signBytes), account.keypair.secretKey) + // logger.debug(sig.join(',')) + // logger.debug(encodeBase64(sig)) // } catch (error) { // logger.error(error) // } diff --git a/src/core/QOSRpc.ts b/src/core/QOSRpc.ts index 5232f2a..df7de54 100644 --- a/src/core/QOSRpc.ts +++ b/src/core/QOSRpc.ts @@ -2,7 +2,6 @@ import Account from './Account'; import SecretKey from './SecretKey'; import Tx from './Tx'; import { IBaseInput } from './types/IBaseInput'; -import { decodeBase64 } from './utils'; import createAxioRequest from './utils/request'; export class QOSRpc { @@ -47,13 +46,17 @@ export class QOSRpc { * 根据私钥恢复账户 * @param {string} privateKey 私钥 */ - public recoveryAccountByPrivateKey(privateKey) { - const privateKeyBuffer = decodeBase64(privateKey); - // const keyPair = nacl.sign.keyPair.fromSecretKey(privateKeyBuffer); - const keyPair = this.key.recoveryKeyPair(privateKeyBuffer) + public recoveryAccountByPrivateKey(privateKey: string) { + const keyPair = this.key.recoveryKeyPair(privateKey) return new Account(this, keyPair); } + // 账户地址格式校验 + public verifyBech32StringByAccAddress(accAddress: string) { + const isValidate = this.key.verifyBech32String(accAddress) + return isValidate; + } + } export default QOSRpc \ No newline at end of file diff --git a/src/core/SecretKey.ts b/src/core/SecretKey.ts index 7ce9889..7ffd8f8 100644 --- a/src/core/SecretKey.ts +++ b/src/core/SecretKey.ts @@ -1,7 +1,7 @@ import { generateMnemonic } from 'bip39'; +import { IAcc } from './types/common'; require('qosKeys'); -import { buf2hex, stringToBuffer } from './utils'; export default class SecretKey { public generateMnemonic() { @@ -10,26 +10,46 @@ export default class SecretKey { return mnemonic; } - public genarateKeyPair(mnemonic: string) { - // const seed = mnemonicToSeedSync(mnemonic); - // 从助记词中获取私钥种子 - const [prikeyBz, pubkeyBz, err] = (global as any).qosKeys.DeriveQOSKey(mnemonic); - // const [privateSeed, err] = (global as any).hdpath.DerivePrivateKeyForPath(secret, chaincode, "44'/389'/0'/0/0") + public genarateKeyPair(mnemonic: string): IAcc { + // 根据助记词得到账户信息 + // @ts-ignore + const [hexprikey, pubkey, accaddr, prikeyBz, pubkeyBz, err] = (global as any).qosKeys.DeriveQOSKey(mnemonic); + return { + address: accaddr, + keyPair: { + hexPrivateKey: hexprikey, + privateKey: prikeyBz, + pubKey: pubkeyBz - if (err != null) { - // tslint:disable-next-line: no-console - console.log(err) + } } - // const secret256 = getHash256(privateSeed); - // const keyPair = ed25519.createKeyPair(new Buffer(secret256)); - // keyPair.bech32pubkey = this.getBech32PubKey(keyPair.publicKey) + } + + public recoveryKeyPair(privateKey: string): IAcc { + // 根据私钥得到账户信息 + // @ts-ignore + const [hexprikey, pubkey, accaddr, prikeyBz, pubkeyBz, err] = (global as any).qosKeys.RecoverFromPrivateKey(privateKey); return { - publicKey: pubkeyBz, - privateKey: prikeyBz, - bech32pubkey: this.getBech32PubKey(pubkeyBz) + address: accaddr, + keyPair: { + hexPrivateKey: hexprikey, + privateKey: prikeyBz, + pubKey: pubkeyBz + } } } + + public verifyBech32String(accAddress: string) { + const isValidate = (global as any).qosKeys.VerifyBech32String(accAddress) + return isValidate + } + + + + + + public getBech32PubKey(publicKey) { const [bech32pubkey, err2] = (global as any).qosKeys.Bech32ifyQOSAccPubKey(publicKey); if (err2 != null) { @@ -37,16 +57,6 @@ export default class SecretKey { } return bech32pubkey } - - public recoveryKeyPair(privateKey: Uint8Array) { - const publicKey = stringToBuffer(buf2hex(privateKey).substring(64, 128), 'hex') - return { - publicKey, - privateKey, - bech32pubkey: this.getBech32PubKey(publicKey) - } - } - public test() { // return keyPair diff --git a/src/core/Txs/Approve.ts b/src/core/Txs/Approve.ts index a880513..45324ee 100644 --- a/src/core/Txs/Approve.ts +++ b/src/core/Txs/Approve.ts @@ -13,7 +13,6 @@ export interface IApproveInput extends IBaseInput { async function sendTx(target: Approve, result: any) { const res = await target.sendTx({ tx: result }) - // logger.debug(res) return res } diff --git a/src/core/Txs/Bank.ts b/src/core/Txs/Bank.ts index b8d2cd6..ee8fade 100644 --- a/src/core/Txs/Bank.ts +++ b/src/core/Txs/Bank.ts @@ -4,7 +4,6 @@ import { componentSignData } from '../common/sign'; import QOSRpc from '../QOSRpc'; import { IQSC } from '../types/common'; import { IBaseInput } from '../types/IBaseInput'; -import logger from '../utils/log'; import Tx from './Tx'; export interface ITransferInput extends IBaseInput { @@ -14,7 +13,6 @@ export interface ITransferInput extends IBaseInput { async function sendTx(target: Bank, result: any) { const res = await target.sendTx({ tx: result }) - logger.debug('res in Bank sendTX ', res) return res } @@ -29,7 +27,6 @@ export default class Bank extends Tx { `/bank/accounts/${address}/transfers`, data ); - logger.debug('execTransfer result', res) return res } @@ -48,7 +45,7 @@ export default class Bank extends Tx { const res = await this.rpc.get( `/accounts/${accountAddress}` ) - logger.debug('execQueryAccount result', res) return res } + } \ No newline at end of file diff --git a/src/core/Txs/Delegation.ts b/src/core/Txs/Delegation.ts index f052102..880aff6 100644 --- a/src/core/Txs/Delegation.ts +++ b/src/core/Txs/Delegation.ts @@ -3,7 +3,6 @@ import { after } from '../common/decorator'; import { componentSignData } from '../common/sign'; import QOSRpc from '../QOSRpc'; import { IBaseInput } from '../types/IBaseInput'; -import logger from '../utils/log'; import Tx from './Tx'; export interface ICreateDelegationInput extends IBaseInput { @@ -22,7 +21,6 @@ export interface IUnbondDelegationInput extends IBaseInput { async function sendTx(target: Delegation, result: any) { const res = await target.sendTx({ tx: result }) - logger.debug('res in sendTX ', res) return res } @@ -37,7 +35,6 @@ export default class Delegation extends Tx { `/stake/delegators/${validatorAddress}/delegations`, data ); - logger.debug('execCreateDelegate result', res) return res } @@ -47,7 +44,6 @@ export default class Delegation extends Tx { `/stake/delegators/${validatorAddress}/modify_delegations`, data ); - logger.debug('execModifyDelegation result', res) return res } @@ -57,7 +53,6 @@ export default class Delegation extends Tx { `/stake/delegators/${validatorAddress}/unbond_delegations`, data ); - logger.debug('execUnbondDelegation result', res) return res } @@ -65,7 +60,6 @@ export default class Delegation extends Tx { const res = await this.rpc.get( `/stake/delegators/${delegatorAddress}/delegations` ); - logger.debug('QueryDelegationsAll result', res) return res } @@ -73,7 +67,13 @@ export default class Delegation extends Tx { const res = await this.rpc.get( `/stake/delegators/${delegatorAddress}/validators/${validatorAddress}` ); - logger.debug('QueryDelegationOne result', res) + return res + } + + public async execQueryValidatorAll(){ + const res = await this.rpc.get( + '/stake/validators' + ) return res } @@ -81,8 +81,9 @@ export default class Delegation extends Tx { const res = await this.rpc.get( `/stake/validators/${validatorAddress}` ) - logger.debug('QueryValidatorOne result', res) return res } + + } \ No newline at end of file diff --git a/src/core/Txs/Tx.ts b/src/core/Txs/Tx.ts index 6731efd..8df6863 100644 --- a/src/core/Txs/Tx.ts +++ b/src/core/Txs/Tx.ts @@ -1,6 +1,5 @@ import QOSRpc from '../..'; import Account from '../Account'; -import logger from '../utils/log'; export default class Tx { public rpc: QOSRpc; @@ -11,7 +10,6 @@ export default class Tx { } public async sendTx({ tx, mode = 'block' }: { tx: string, mode?: 'block' | 'sync' | 'async'}) { - logger.debug('sendTx:===', JSON.stringify({ tx, mode })) const res = await this.rpc.request({ method: 'POST', url: '/txs', diff --git a/src/core/common/decorator.ts b/src/core/common/decorator.ts index f26a1a9..69e81bd 100644 --- a/src/core/common/decorator.ts +++ b/src/core/common/decorator.ts @@ -1,13 +1,10 @@ -import logger from '../utils/log'; - export function after(...args) { - return (_target, name, descriptor) => { + return (_target, _key, descriptor) => { // 获取value,其实就是原函数 const oldValue = descriptor.value; // 将value重新赋值一个函数 descriptor.value = async function () { // tslint:disable-next-line: no-console - logger.debug(`Calling ${name} with`, arguments); // 将原本的函数执行一下,apply改变this的指向 const val = await oldValue.apply(this, arguments) let result = val; diff --git a/src/core/common/sign.ts b/src/core/common/sign.ts index b1228b2..f0a05c4 100644 --- a/src/core/common/sign.ts +++ b/src/core/common/sign.ts @@ -3,31 +3,28 @@ require('qosKeys'); import Account from '../Account'; import Tx from '../Txs/Tx'; -import { decodeBase64, encodeBase64 } from '../utils'; -import logger from '../utils/log'; +import { encodeBase64 } from '../utils'; export function sign(account: Account, data: any) { // const sig = nacl.sign.detached(decodeBase64(data), account.keypair.privateKey) // const sig = ed25519.Sign(decodeBase64(data), account.keypair.privateKey); - const sig = (global as any).qosKeys.Sign(account.keypair.privateKey, decodeBase64(data)); + const sig = (global as any).qosKeys.SignBase64Message(account.keypair.hexPrivateKey, data); // logger.debug('sig', encodeBase64(sig)) return encodeBase64(sig) } -export function componentSignData(target: Tx, res: any) { +export async function componentSignData(target: Tx, res: any) { const sig = sign((target as any).account, res.data.sign_bytes) const resObj = JSON.parse(res.data.tx) - logger.debug('target', target) - logger.debug('res', res) + const pubkeyBase64 = (global as any).qosKeys.EncodeBase64(target.account.pubKeyBz) + resObj.value.sigature[0].signature = sig resObj.value.sigature[0].pubkey = { - type: 'tendermint/PubKeyEd25519', - // 'value': 'lDomDLEe+ou01k4FsNLJOdU10rhlpBxVQR+BAwSpUzc=' - value: target.account.pubKey + type: 'tendermint/PubKeyEd25519', + // 'value': 'lDomDLEe+ou01k4FsNLJOdU10rhlpBxVQR+BAwSpUzc=' + value: pubkeyBase64 } - logger.debug('resobj', resObj) - logger.debug('itx', resObj.value.itx[0]) return resObj } \ No newline at end of file diff --git a/src/core/types/common.ts b/src/core/types/common.ts index cc002c2..1f107d2 100644 --- a/src/core/types/common.ts +++ b/src/core/types/common.ts @@ -1,7 +1,15 @@ export interface IKeyPair { - publicKey: Uint8Array; privateKey: Uint8Array; - bech32pubkey: string; + pubKey: Uint8Array; + hexPrivateKey: string; + // accAddress: string; + // privateKeyBz: string; + // pubKeyBz: string; +} + +export interface IAcc { + address: string, + keyPair: IKeyPair } export interface IQSC { diff --git a/src/core/utils/log.ts b/src/core/utils/log.ts deleted file mode 100644 index 9a9b6ee..0000000 --- a/src/core/utils/log.ts +++ /dev/null @@ -1,8 +0,0 @@ -import log4js from 'log4js'; -log4js.configure({ - appenders: { log: { type: 'file', filename: 'log/log.log' } }, - categories: { default: { appenders: ['log'], level: 'debug' } } -}); -const logger = log4js.getLogger('log'); - -export default logger; diff --git a/yarn.lock b/yarn.lock index 376adf8..bf00b3f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3550,7 +3550,7 @@ q@^1.5.1: "qosKeys@https://github.com/QOSGroup/js-keys": version "1.0.2" - resolved "https://github.com/QOSGroup/js-keys#72437102b07cbdf662c8ab1cf12472c508451522" + resolved "https://github.com/QOSGroup/js-keys#391cdf9471c26349eb15bb7cd375836cd58b253c" query-string@^4.1.0: version "4.3.4"