Cleanup code and preparation for chat reference

This commit is contained in:
AlphaX-Projects 2023-01-13 09:52:14 +01:00
parent 8edd13a083
commit b6f567c584
58 changed files with 2197 additions and 2446 deletions

View File

@ -2,9 +2,8 @@ import { Sha256 } from 'asmcrypto.js'
import Base58 from './api/deps/Base58'
import { base58PublicKeyToAddress } from './api/wallet/base58PublicKeyToAddress'
import { validateAddress } from './api/wallet/validateAddress'
import { decryptChatMessage } from './api/transactions/chat/decryptChatMessage';
import _ from 'lodash';
import { decryptChatMessage } from './api/transactions/chat/decryptChatMessage'
import _ from 'lodash'
window.Sha256 = Sha256
window.Base58 = Base58
@ -14,7 +13,6 @@ window.validateAddress = validateAddress
window.decryptChatMessage = decryptChatMessage
export { initApi, store } from './api_deps.js'
export * from './api/deps/deps.js'
export * from './api/api.js'
export * from './api/registerUsername.js'

View File

@ -1,7 +1,7 @@
/*
Copyright 2017-2018 @ irontiga and vbcs (original developer)
*/
'use strict';
'use strict'
import Base58 from './deps/Base58.js'
import { Sha256, Sha512 } from 'asmcrypto.js'
import nacl from './deps/nacl-fast.js'
@ -10,7 +10,7 @@ import utils from './deps/utils.js'
import { generateSaveWalletData } from './storeWallet.js'
import publicKeyToAddress from './wallet/publicKeyToAddress.js'
import AltcoinHDWallet from "./bitcoin/AltcoinHDWallet";
import AltcoinHDWallet from "./bitcoin/AltcoinHDWallet"
export default class PhraseWallet {
constructor(seed, walletVersion) {

View File

@ -1,9 +1,5 @@
export { request } from './fetch-request.js'
export { transactionTypes as transactions } from './transactions/transactions.js'
export { processTransaction, createTransaction, computeChatNonce, signChatTransaction, signArbitraryTransaction } from './createTransaction.js'
export { tradeBotCreateRequest, tradeBotRespondRequest, signTradeBotTxn, deleteTradeOffer, sendBtc, sendLtc, sendDoge, sendDgb, sendRvn, sendArrr } from './tradeRequest.js'
export { cancelAllOffers } from './transactions/trade-portal/tradeoffer/cancelAllOffers.js'

View File

@ -1,11 +1,10 @@
'use strict';
import Base58 from '../deps/Base58.js'
import { Sha256, Sha512 } from 'asmcrypto.js'
import jsSHA from "jssha";
import jsSHA from 'jssha'
import RIPEMD160 from '../deps/ripemd160.js'
import utils from '../deps/utils.js'
import { EllipticCurve, BigInteger } from './ecbn.js';
import { EllipticCurve, BigInteger } from './ecbn.js'
export default class AltcoinHDWallet {
@ -101,14 +100,10 @@ export default class AltcoinHDWallet {
this._tmasterPublicKey = ''
/**
* Child Keys Derivation from the Parent Keys
*/
/**
* Child Private Key - 32 bytes
*/
@ -145,13 +140,10 @@ export default class AltcoinHDWallet {
this.xPublicChildKey = ''
/**
* Grand Child Keys Derivation from the Child Keys
*/
/**
* Grand Child Private Key - 32 bytes
*/
@ -200,7 +192,6 @@ export default class AltcoinHDWallet {
this._tlitecoinLegacyAddress = ''
/**
* Wallet - Wallet Object (keys...)
*/
@ -250,76 +241,69 @@ export default class AltcoinHDWallet {
generateSeedHash(seed, isBIP44, indicator = null) {
let buffer;
let buffer
if (isBIP44) {
buffer = utils.appendBuffer(seed.reverse(), utils.int32ToBytes(indicator))
} else {
if(indicator !== null) {
const indicatorString = utils.stringtoUTF8Array(indicator);
buffer = utils.appendBuffer(seed.reverse(), indicatorString);
const indicatorString = utils.stringtoUTF8Array(indicator)
buffer = utils.appendBuffer(seed.reverse(), indicatorString)
}
else
{
buffer = seed.reverse();
buffer = seed.reverse()
}
}
const _reverseSeedHash = new Sha256().process(buffer).finish().result;
this.seedHash = new Sha512().process(utils.appendBuffer(seed, _reverseSeedHash)).finish().result;
const _reverseSeedHash = new Sha256().process(buffer).finish().result
this.seedHash = new Sha512().process(utils.appendBuffer(seed, _reverseSeedHash)).finish().result
}
generatePrivateKey(seedHash) {
const SECP256K1_CURVE_ORDER = new BigInteger("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141")
const SECP256K1_CURVE_ORDER = new BigInteger("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141");
const privateKeyHash = seedHash.slice(0, 32)
const privateKeyHash = seedHash.slice(0, 32);
this.seed58 = Base58.encode(privateKeyHash);
this.seed58 = Base58.encode(privateKeyHash)
const _privateKeyHash = [...privateKeyHash]
let privateKeyBigInt = BigInteger.fromByteArrayUnsigned(_privateKeyHash);
let privateKeyBigInt = BigInteger.fromByteArrayUnsigned(_privateKeyHash)
const privateKey = (privateKeyBigInt.mod(SECP256K1_CURVE_ORDER.subtract(BigInteger.ONE))).add(BigInteger.ONE)
this.privateKey = privateKey.toByteArrayUnsigned()
}
generateChainCode(seedHash) {
this.chainCode = new Sha256().process(seedHash.slice(32, 64)).finish().result;
this.chainCode = new Sha256().process(seedHash.slice(32, 64)).finish().result
}
generatePublicKey(privateKey) {
const _privateKey = [...privateKey]
const privateKeyBigInt = BigInteger.fromByteArrayUnsigned(_privateKey);
const privateKeyBigInt = BigInteger.fromByteArrayUnsigned(_privateKey)
const epCurve = EllipticCurve.getSECCurveByName("secp256k1");
const curvePoints = epCurve.getG().multiply(privateKeyBigInt);
const epCurve = EllipticCurve.getSECCurveByName("secp256k1")
const curvePoints = epCurve.getG().multiply(privateKeyBigInt)
const x = curvePoints.getX().toBigInteger();
const y = curvePoints.getY().toBigInteger();
const x = curvePoints.getX().toBigInteger()
const y = curvePoints.getY().toBigInteger()
/**
* Deriving Uncompressed Public Key (65 bytes)
*
* const publicKeyBytes = EllipticCurve.integerToBytes(x, 32);
* this.publicKey = publicKeyBytes.concat(EllipticCurve.integerToBytes(y, 32));
* this.publicKey.unshift(0x04); // append point indicator
* const publicKeyBytes = EllipticCurve.integerToBytes(x, 32)
* this.publicKey = publicKeyBytes.concat(EllipticCurve.integerToBytes(y, 32))
* this.publicKey.unshift(0x04) // append point indicator
*/
// Compressed Public Key (33 bytes)
this.publicKey = EllipticCurve.integerToBytes(x, 32)
if (y.isEven()) {
this.publicKey.unshift(0x02) // append point indicator
} else {
this.publicKey.unshift(0x03) // append point indicator
}
@ -330,7 +314,6 @@ export default class AltcoinHDWallet {
}
generateMainnetMasterPrivateKey() {
// Serialization Variable
const s = []
@ -375,7 +358,6 @@ export default class AltcoinHDWallet {
}
generateMainnetMasterPublicKey() {
// Serialization Variable
const s = []
@ -495,19 +477,19 @@ export default class AltcoinHDWallet {
// TODO: Make this more better in the future
const path = 'm/0/0'
// let p = path.split('/');
// let p = path.split('/')
// Get Public kEY
const derivePublicChildKey = () => {
const _privateKey = [...this.childPrivateKey]
const privateKeyBigInt = BigInteger.fromByteArrayUnsigned(_privateKey);
const privateKeyBigInt = BigInteger.fromByteArrayUnsigned(_privateKey)
const epCurve = EllipticCurve.getSECCurveByName("secp256k1");
const curvePoints = epCurve.getG().multiply(privateKeyBigInt);
const epCurve = EllipticCurve.getSECCurveByName("secp256k1")
const curvePoints = epCurve.getG().multiply(privateKeyBigInt)
const x = curvePoints.getX().toBigInteger();
const y = curvePoints.getY().toBigInteger();
const x = curvePoints.getX().toBigInteger()
const y = curvePoints.getY().toBigInteger()
// Compressed Public Key (33 bytes)
this.childPublicKey = EllipticCurve.integerToBytes(x, 32)
@ -533,15 +515,15 @@ export default class AltcoinHDWallet {
const derivePrivateChildKey = (cI) => {
let ib = [];
ib.push((cI >> 24) & 0xff);
ib.push((cI >> 16) & 0xff);
ib.push((cI >> 8) & 0xff);
ib.push(cI & 0xff);
let ib = []
ib.push((cI >> 24) & 0xff)
ib.push((cI >> 16) & 0xff)
ib.push((cI >> 8) & 0xff)
ib.push(cI & 0xff)
const s = [...this.publicKey].concat(ib);
const s = [...this.publicKey].concat(ib)
const _hmacSha512 = new jsSHA("SHA-512", "UINT8ARRAY", { numRounds: 1, hmacKey: { value: this.chainCode, format: "UINT8ARRAY" } });
const _hmacSha512 = new jsSHA("SHA-512", "UINT8ARRAY", { numRounds: 1, hmacKey: { value: this.chainCode, format: "UINT8ARRAY" } })
_hmacSha512.update(new Uint8Array(s))
@ -550,10 +532,10 @@ export default class AltcoinHDWallet {
// SECP256k1 init
const epCurve = EllipticCurve.getSECCurveByName("secp256k1");
const epCurve = EllipticCurve.getSECCurveByName("secp256k1")
const ki = IL.add(BigInteger.fromByteArrayUnsigned(this.privateKey)).mod(epCurve.getN()); // parse256(IL) + kpar (mod n) ==> ki
const ki = IL.add(BigInteger.fromByteArrayUnsigned(this.privateKey)).mod(epCurve.getN()) // parse256(IL) + kpar (mod n) ==> ki
this.childPrivateKey = ki.toByteArrayUnsigned()
// Call deriveExtendedPrivateChildKey
@ -577,10 +559,10 @@ export default class AltcoinHDWallet {
s.push(...(this.publicKeyHash.slice(0, 4)))
// Append Child Index
s.push(childIndex >>> 24);
s.push((childIndex >>> 16) & 0xff);
s.push((childIndex >>> 8) & 0xff);
s.push(childIndex & 0xff);
s.push(childIndex >>> 24)
s.push((childIndex >>> 16) & 0xff)
s.push((childIndex >>> 8) & 0xff)
s.push(childIndex & 0xff)
// Append Chain Code
s.push(...this.childChainCode)
@ -619,10 +601,10 @@ export default class AltcoinHDWallet {
s.push(...(this.publicKeyHash.slice(0, 4)))
// Append Child Index
s.push(childIndex >>> 24);
s.push((childIndex >>> 16) & 0xff);
s.push((childIndex >>> 8) & 0xff);
s.push(childIndex & 0xff);
s.push(childIndex >>> 24)
s.push((childIndex >>> 16) & 0xff)
s.push((childIndex >>> 8) & 0xff)
s.push(childIndex & 0xff)
// Append Chain Code
s.push(...this.childChainCode)
@ -654,24 +636,22 @@ export default class AltcoinHDWallet {
const derivePublicGrandChildKey = () => {
const _privateKey = [...this.grandChildPrivateKey]
const privateKeyBigInt = BigInteger.fromByteArrayUnsigned(_privateKey);
const privateKeyBigInt = BigInteger.fromByteArrayUnsigned(_privateKey)
const epCurve = EllipticCurve.getSECCurveByName("secp256k1");
const curvePoints = epCurve.getG().multiply(privateKeyBigInt);
const epCurve = EllipticCurve.getSECCurveByName("secp256k1")
const curvePoints = epCurve.getG().multiply(privateKeyBigInt)
const x = curvePoints.getX().toBigInteger();
const y = curvePoints.getY().toBigInteger();
const x = curvePoints.getX().toBigInteger()
const y = curvePoints.getY().toBigInteger()
// Compressed Public Key (33 bytes)
this.grandChildPublicKey = EllipticCurve.integerToBytes(x, 32)
if (y.isEven()) {
this.grandChildPublicKey.unshift(0x02) // append point indicator
} else {
this.grandChildPublicKey.unshift(0x03) // append point indicator
}
@ -729,16 +709,16 @@ export default class AltcoinHDWallet {
const derivePrivateGrandChildKey = (cI, i) => {
let ib = [];
ib.push((cI >> 24) & 0xff);
ib.push((cI >> 16) & 0xff);
ib.push((cI >> 8) & 0xff);
ib.push(cI & 0xff);
let ib = []
ib.push((cI >> 24) & 0xff)
ib.push((cI >> 16) & 0xff)
ib.push((cI >> 8) & 0xff)
ib.push(cI & 0xff)
const s = [...this.childPublicKey].concat(ib);
const s = [...this.childPublicKey].concat(ib)
const _hmacSha512 = new jsSHA("SHA-512", "UINT8ARRAY", { numRounds: 1, hmacKey: { value: this.childChainCode, format: "UINT8ARRAY" } });
const _hmacSha512 = new jsSHA("SHA-512", "UINT8ARRAY", { numRounds: 1, hmacKey: { value: this.childChainCode, format: "UINT8ARRAY" } })
_hmacSha512.update(new Uint8Array(s))
@ -746,10 +726,10 @@ export default class AltcoinHDWallet {
this.grandChildChainCode = _hmacSha512.getHMAC('UINT8ARRAY').slice(32, 64) // IR according to the SPEC
// SECP256k1 init
const epCurve = EllipticCurve.getSECCurveByName("secp256k1");
const epCurve = EllipticCurve.getSECCurveByName("secp256k1")
const ki = IL.add(BigInteger.fromByteArrayUnsigned(this.childPrivateKey)).mod(epCurve.getN()); // parse256(IL) + kpar (mod n) ==> ki
const ki = IL.add(BigInteger.fromByteArrayUnsigned(this.childPrivateKey)).mod(epCurve.getN()) // parse256(IL) + kpar (mod n) ==> ki
this.grandChildPrivateKey = ki.toByteArrayUnsigned()
@ -774,10 +754,10 @@ export default class AltcoinHDWallet {
s.push(...(this.childPublicKeyHash.slice(0, 4)))
// Append Child Index
s.push(childIndex >>> 24);
s.push((childIndex >>> 16) & 0xff);
s.push((childIndex >>> 8) & 0xff);
s.push(childIndex & 0xff);
s.push(childIndex >>> 24)
s.push((childIndex >>> 16) & 0xff)
s.push((childIndex >>> 8) & 0xff)
s.push(childIndex & 0xff)
// Append Chain Code
s.push(...this.grandChildChainCode)
@ -816,10 +796,10 @@ export default class AltcoinHDWallet {
s.push(...(this.childPublicKeyHash.slice(0, 4)))
// Append Child Index
s.push(childIndex >>> 24);
s.push((childIndex >>> 16) & 0xff);
s.push((childIndex >>> 8) & 0xff);
s.push(childIndex & 0xff);
s.push(childIndex >>> 24)
s.push((childIndex >>> 16) & 0xff)
s.push((childIndex >>> 8) & 0xff)
s.push(childIndex & 0xff)
// Append Chain Code
s.push(...this.grandChildChainCode)

View File

@ -1,4 +1,4 @@
"use strict";
'use strict'
// Qortal TX types
const TX_TYPES = {
@ -158,6 +158,9 @@ const ADDRESS_VERSION = 58
// Proxy for api calls
const PROXY_URL = "/proxy/"
// Chat reference timestamp
const CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP = 9999999999999
// Used as a salt for all qora addresses. Salts used for storing your private keys in local storage will be randomly generated
const STATIC_SALT = new Uint8Array([54, 190, 201, 206, 65, 29, 123, 129, 147, 231, 180, 166, 171, 45, 95, 165, 78, 200, 208, 194, 44, 207, 221, 146, 45, 238, 68, 68, 69, 102, 62, 6])
const BCRYPT_ROUNDS = 10 // Remember that the total work spent on key derivation is BCRYPT_ROUNDS * KDF_THREADS
@ -165,4 +168,4 @@ const BCRYPT_VERSION = "2a"
const STATIC_BCRYPT_SALT = `$${BCRYPT_VERSION}$${BCRYPT_ROUNDS}$IxVE941tXVUD4cW0TNVm.O`
const KDF_THREADS = 16
export { TX_TYPES, ERROR_CODES, QORT_DECIMALS, PROXY_URL, STATIC_SALT, ADDRESS_VERSION, KDF_THREADS, STATIC_BCRYPT_SALT }
export { TX_TYPES, ERROR_CODES, QORT_DECIMALS, PROXY_URL, STATIC_SALT, ADDRESS_VERSION, KDF_THREADS, STATIC_BCRYPT_SALT, CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP }

View File

@ -8,21 +8,14 @@ const CHECK_LAST_REF_INTERVAL = 30 * 1000 // err 30 seconds
const pendingAddresses = {}
// const config = store.getState().config
// const node = config.coin.node.api
// const baseUrl = node.url + node.tail
const checkLastRefs = () => {
Object.entries(pendingAddresses).forEach(([address, fn]) => {
// console.log(fn, address)
request('addresses/lastreference/' + address).then(res => {
if (res === 'false') return
fn(res)
delete pendingAddresses[address]
clearInterval(lastRefInterval)
})
// fetch(baseUrl + 'addresses/lastreference/' + address)
// .then(async res => res.text())
})
}

View File

@ -1,6 +1,5 @@
import { HmacSha512, AES_CBC } from 'asmcrypto.js'
import { kdf } from './kdf.js'
// import Base58 from '../qora/deps/Base58.js'
import Base58 from './deps/Base58.js'
const getRandomValues = window.crypto ? window.crypto.getRandomValues.bind(window.crypto) : window.msCrypto.getRandomValues.bind(window.msCrypto)
@ -10,15 +9,12 @@ export const generateSaveWalletData = async (wallet, password, kdfThreads, statu
let iv = new Uint8Array(16)
getRandomValues(iv)
let salt = new Uint8Array(32)
getRandomValues(salt) // Can actually use a salt this time, as we can store the salt with the wallet
// const key = PBKDF2_HMAC_SHA512.bytes(utils.stringtoUTF8Array(password), salt, PBKDF2_ROUNDS, 64) // 512bit key to be split in two for mac/encryption
getRandomValues(salt)
const key = await kdf(password, salt, statusUpdateFn)
statusUpdateFn('Encrypting seed')
const encryptionKey = key.slice(0, 32)
const macKey = key.slice(32, 63)
const encryptedSeed = AES_CBC.encrypt(wallet._byteSeed, encryptionKey, false, iv)
// const mac = HmacSha512.bytes(encryptedSeed, macKey)
statusUpdateFn('Generating mac')
const mac = new HmacSha512(macKey).process(encryptedSeed).finish().result
return {

View File

@ -1,18 +1,14 @@
// Trade Bot
import TradeBotCreateRequest from './transactions/trade-portal/tradebot/TradeBotCreateRequest.js';
import TradeBotRespondRequest from './transactions/trade-portal/tradebot/TradeBotRespondRequest.js';
import TradeBotCreateRequest from './transactions/trade-portal/tradebot/TradeBotCreateRequest.js'
import TradeBotRespondRequest from './transactions/trade-portal/tradebot/TradeBotRespondRequest.js'
import signTradeBotTransaction from './transactions/trade-portal/tradebot/signTradeBotTransaction.js'
// Trade Offer
import DeleteTradeOffer from './transactions/trade-portal/tradeoffer/DeleteTradeOffer.js';
import DeleteTradeOffer from './transactions/trade-portal/tradeoffer/DeleteTradeOffer.js'
import { request } from './fetch-request'
// TradeBotCreateRequest
export const tradeBotCreateRequest = (requestObject) => {
const txn = new TradeBotCreateRequest().createTransaction(requestObject)
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node];
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node]
return request(`/crosschain/tradebot/create?apiKey=${myNode.apiKey}`, {
method: 'POST',
@ -27,7 +23,7 @@ export const tradeBotCreateRequest = (requestObject) => {
// TradeBotRespondRequest
export const tradeBotRespondRequest = (requestObject) => {
const txn = new TradeBotRespondRequest().createTransaction(requestObject)
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node];
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node]
return request(`/crosschain/tradebot/respond?apiKey=${myNode.apiKey}`, {
method: 'POST',
@ -39,7 +35,6 @@ export const tradeBotRespondRequest = (requestObject) => {
})
}
// Sign Trade Transactions
export const signTradeBotTxn = (unsignedTxn, keyPair) => {
return signTradeBotTransaction(unsignedTxn, keyPair)
@ -48,7 +43,7 @@ export const signTradeBotTxn = (unsignedTxn, keyPair) => {
// Delete Trade Offer
export const deleteTradeOffer = (requestObject) => {
const txn = new DeleteTradeOffer().createTransaction(requestObject)
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node];
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node]
return request(`/crosschain/tradeoffer?apiKey=${myNode.apiKey}`, {
method: 'DELETE',
@ -62,7 +57,7 @@ export const deleteTradeOffer = (requestObject) => {
// Send BTC
export const sendBtc = (requestObject) => {
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node];
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node]
return request(`/crosschain/btc/send?apiKey=${myNode.apiKey}`, {
method: 'POST',
@ -76,7 +71,7 @@ export const sendBtc = (requestObject) => {
// Send LTC
export const sendLtc = (requestObject) => {
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node];
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node]
return request(`/crosschain/ltc/send?apiKey=${myNode.apiKey}`, {
method: 'POST',
@ -90,7 +85,7 @@ export const sendLtc = (requestObject) => {
// Send DOGE
export const sendDoge = (requestObject) => {
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node];
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node]
return request(`/crosschain/doge/send?apiKey=${myNode.apiKey}`, {
method: 'POST',
@ -104,7 +99,7 @@ export const sendDoge = (requestObject) => {
// Send DGB
export const sendDgb = (requestObject) => {
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node];
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node]
return request(`/crosschain/dgb/send?apiKey=${myNode.apiKey}`, {
method: 'POST',
@ -118,7 +113,7 @@ export const sendDgb = (requestObject) => {
// Send RVN
export const sendRvn = (requestObject) => {
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node];
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node]
return request(`/crosschain/rvn/send?apiKey=${myNode.apiKey}`, {
method: 'POST',
@ -132,7 +127,7 @@ export const sendRvn = (requestObject) => {
// Send ARRR
export const sendArrr = (requestObject) => {
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node];
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node]
return request(`/crosschain/arrr/send?apiKey=${myNode.apiKey}`, {
method: 'POST',

View File

@ -1,32 +1,17 @@
'use strict';
'use strict'
import TransactionBase from './TransactionBase.js'
import { QORT_DECIMALS } from '../constants.js'
// import { Sha256 } from 'asmcrypto.js/dist_es5/entry-export_all.js'
export default class PaymentTransaction extends TransactionBase {
constructor() {
super()
this.type = 20
this.amount = 42 * Math.pow(10, 8)
this.tests.push(
() => {
if (!(this._amount >= 0)) {
return 'Invalid amount ' + this._amount / QORT_DECIMALS
}
return true
},
() => {
if (!(this._recipient instanceof Uint8Array && this._recipient.length == 25)) {
return 'Invalid recipient ' + Base58.encode(this._recipient)
}
return true
}
)
}
set recipient (recipient) { // Always Base58 encoded. Accepts Uint8Array or Base58 string.
set recipient(recipient) {
this._recipient = recipient instanceof Uint8Array ? recipient : this.constructor.Base58.decode(recipient)
}
set amount(amount) {
this._amount = amount * QORT_DECIMALS
this._amountBytes = this.constructor.utils.int64ToBytes(amount)

View File

@ -1,22 +1,13 @@
'use strict';
'use strict'
import TransactionBase from './TransactionBase.js'
// import { QORT_DECIMALS } from "../constants.js" // Not needed, no amount
export default class DelegationTransaction extends TransactionBase {
constructor() {
super()
this.type = 18
this.tests.push(
() => {
if (!(this._superNodeAddress instanceof Uint8Array && this._superNodeAddress.length == 25)) {
return 'Invalid recipient ' + Base58.encode(this._superNodeAddress)
}
return true
}
)
}
set superNodeAddress (superNodeAddress) { // Always Base58 encoded. Accepts Uint8Array or Base58 string.
set superNodeAddress(superNodeAddress) {
this._superNodeAddress = superNodeAddress instanceof Uint8Array ? superNodeAddress : this.constructor.Base58.decode(superNodeAddress)
}

View File

@ -1,14 +1,10 @@
"use strict";
import PaymentTransaction from "./PaymentTransaction.js"
import { QORT_DECIMALS } from "../constants.js"
/* ====================================
EXTEND THE PAYMENT TRANSACTION YOU CLOWN
====================================== */
'use strict'
import PaymentTransaction from './PaymentTransaction.js'
import { QORT_DECIMALS } from '../constants.js'
export default class MessageTransaction extends PaymentTransaction {
constructor() {
super();
super()
this.type = 17
this._key = this.constructor.utils.int64ToBytes(0);
this._isEncrypted = new Uint8Array(1); // Defaults to false
@ -17,22 +13,22 @@ export default class MessageTransaction extends PaymentTransaction{
set message(message /* UTF8 String */) {
// ...yes? no?
this.messageText = message;
this.messageText = message
// Not sure about encoding here...
//this._message = message instanceof Uint8Array ? message : this.constructor.Base58.decode(message);
this._message = this.constructor.utils.stringtoUTF8Array(message)
this._messageLength = this.constructor.utils.int64ToBytes(this._message.length)
}
set isEncrypted(isEncrypted) {
this._isEncrypted[0] = isEncrypted;
this._isEncrypted[0] = isEncrypted
}
set isText(isText) {
this._isText[0] = isText;
this._isText[0] = isText
}
get _params() {
// dont extend super because paymentTrasaction is different
//const params = super.params;
return [
this._typeBytes,
this._timestampBytes,
@ -49,47 +45,3 @@ export default class MessageTransaction extends PaymentTransaction{
]
}
}
//"use strict";
//function generateSignatureMessageTransaction(keyPair, lastReference, recipient, amount, fee, timestamp, message, isText, isEncrypted) => {
// const data = generateMessageTransactionBase(keyPair.publicKey, lastReference, recipient, amount, fee, timestamp, message, isText, isEncrypted);
// return nacl.sign.detached(data, keyPair.privateKey);
//}
//
//function generateMessageTransaction(keyPair, lastReference, recipient, amount, fee, timestamp, message, isText, isEncrypted, signature) => {
// return appendBuffer(generateMessageTransactionBase(keyPair.publicKey, lastReference, recipient, amount, fee, timestamp, message, isText, isEncrypted),
// signature);
//}
//function generateMessageTransactionBase(publicKey, lastReference, recipient, amount, fee, timestamp, message, isText, isEncrypted) => {
// txType = TYPES.MESSAGE_TRANSACTION;
//
// const typeBytes = int32ToBytes(txType);
// const timestampBytes = int64ToBytes(timestamp);
// const amountBytes = int64ToBytes(amount * 100000000);
// const feeBytes = int64ToBytes(fee * 100000000);
// const messageLength = int32ToBytes(message.length);
// const key = int64ToBytes(0);
//
// isTextB = new Uint8Array(1);
// isTextB[0] = isText;
//
// isEncryptedB = new Uint8Array(1);
// isEncryptedB[0] = isEncrypted;
//
// let data = new Uint8Array();
//
// data = appendBuffer(data, typeBytes);
// data = appendBuffer(data, timestampBytes);
// data = appendBuffer(data, lastReference);
// data = appendBuffer(data, publicKey);
// data = appendBuffer(data, recipient);
// data = appendBuffer(data, key);
// data = appendBuffer(data, amountBytes);
// data = appendBuffer(data, messageLength);
// data = appendBuffer(data, message);
// data = appendBuffer(data, isEncryptedB);
// data = appendBuffer(data, isTextB);
// data = appendBuffer(data, feeBytes);
//
// return data;
//}

View File

@ -1,4 +1,4 @@
'use strict';
'use strict'
import TransactionBase from './TransactionBase.js'
import Base58 from '../deps/Base58.js'
import { store } from '../../api.js'
@ -7,23 +7,34 @@ export default class PaymentTransaction extends TransactionBase {
constructor() {
super()
this.type = 2
this.tests.push(
() => {
if (!(this._amount >= 0)) {
return 'Invalid amount ' + this._amount / store.getState().config.coin.decimals
}
return true
},
() => {
if (!(this._recipient instanceof Uint8Array && this._recipient.length == 25)) {
return 'Invalid recipient ' + Base58.encode(this._recipient)
}
return true
}
)
}
set recipient(recipient) { // Always Base58 encoded. Accepts Uint8Array or Base58 string.
render(html) {
const conf = store.getState().config
return html`
<table>
<tr>
<th>${this._dialogto}:</th>
</tr>
<tr>
<td>${this.dialogAddress} ${' '}-</td>
<td>${Base58.encode(this._recipient)}</td>
</tr>
${this.recipientName ? html`
<tr>
<td>${this.dialogName} ${' '}-</td>
<td>${this.recipientName}</td>
</tr>
` : ''}
<tr>
<th>${this._dialogamount}</th>
<td>${this._amount / conf.coin.decimals} ${conf.coin.symbol}</td>
</tr>
</table>
`
}
set recipient(recipient) {
this._recipient = recipient instanceof Uint8Array ? recipient : this.constructor.Base58.decode(recipient)
}
@ -49,32 +60,4 @@ export default class PaymentTransaction extends TransactionBase {
)
return params
}
render(html) {
const conf = store.getState().config
return html`
<table>
<tr>
<th>${this._dialogto}:</th>
</tr>
<tr>
<td>${this.dialogAddress} ${' '}-</td>
<td>${Base58.encode(this._recipient)}</td>
</tr>
${this.recipientName ? html`
<tr>
<td>${this.dialogName} ${' '}-</td>
<td>${this.recipientName}</td>
</tr>
` : ''}
<tr>
<th>${this._dialogamount}</th>
<td>${this._amount / conf.coin.decimals} ${conf.coin.symbol}</td>
</tr>
</table>
`
}
}

View File

@ -1,9 +1,9 @@
"use strict";
import ChatBase from "./chat/ChatBase.js"
'use strict'
import ChatBase from './chat/ChatBase.js'
export default class PublicizeTransaction extends ChatBase {
constructor() {
super();
super()
this.type = 19
this.fee = 0
}
@ -13,11 +13,11 @@ export default class PublicizeTransaction extends ChatBase {
}
get params() {
const params = super.params;
const params = super.params
params.push(
this._proofOfWorkNonce,
this._feeBytes
)
return params;
return params
}
}

View File

@ -1,4 +1,4 @@
'use strict';
'use strict'
import { TX_TYPES, QORT_DECIMALS } from '../constants.js'
import nacl from '../deps/nacl-fast.js'
import Base58 from '../deps/Base58.js'
@ -16,84 +16,44 @@ export default class TransactionBase {
}
constructor() {
// Defaults
this.fee = 0
this.groupID = 0
this.timestamp = Date.now()
this.tests = [
() => {
if (!(this._type >= 1 && this._type in TX_TYPES)) {
return 'Invalid type: ' + this.type
}
return true
},
() => {
if (this._fee < 0) {
return 'Invalid fee: ' + this._fee / QORT_DECIMALS
}
return true
},
() => {
if (this._groupID < 0 || !Number.isInteger(this._groupID)) {
return 'Invalid groupID: ' + this._groupID
}
return true
},
() => {
if (!(new Date(this._timestamp)).getTime() > 0) {
return 'Invalid timestamp: ' + this._timestamp
}
return true
},
() => {
if (!(this._lastReference instanceof Uint8Array && this._lastReference.byteLength == 64)) {
if (this._lastReference == 0) {
// No prior transactions exist
return 'Invalid last reference. Please ensure that you have at least 0.001 QORT for the transaction fee.'
}
return 'Invalid last reference: ' + this._lastReference
}
return true
},
() => {
if (!(this._keyPair)) {
return 'keyPair must be specified'
}
if (!(this._keyPair.publicKey instanceof Uint8Array && this._keyPair.publicKey.byteLength === 32)) {
return 'Invalid publicKey'
}
if (!(this._keyPair.privateKey instanceof Uint8Array && this._keyPair.privateKey.byteLength === 64)) {
return 'Invalid privateKey'
}
return true
}
]
render(html) {
return html`render method to display requested transaction info`
}
set keyPair(keyPair) {
this._keyPair = keyPair
}
set type(type) {
this.typeText = TX_TYPES[type]
this._type = type
this._typeBytes = this.constructor.utils.int32ToBytes(this._type)
}
set groupID(groupID) {
this._groupID = groupID
this._groupIDBytes = this.constructor.utils.int32ToBytes(this._groupID)
}
set timestamp(timestamp) {
this._timestamp = timestamp
this._timestampBytes = this.constructor.utils.int64ToBytes(this._timestamp)
}
set fee(fee) {
this._fee = fee * QORT_DECIMALS
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee)
}
set lastReference(lastReference) { // Always Base58 encoded. Accepts Uint8Array or Base58 string.
// lastReference could be a string or an Uint8Array
set lastReference(lastReference) {
this._lastReference = lastReference instanceof Uint8Array ? lastReference : this.constructor.Base58.decode(lastReference)
}
get params() {
return [
this._typeBytes,
@ -103,6 +63,7 @@ export default class TransactionBase {
this._keyPair.publicKey
]
}
get signedBytes() {
if (!this._signedBytes) {
this.sign()
@ -110,16 +71,10 @@ export default class TransactionBase {
return this._signedBytes
}
// render function but NOT lit element
render(html) {
return html`render method to display requested transaction info`
}
validParams() {
let finalResult = {
valid: true
}
// const valid =
this.tests.some(test => {
const result = test()
if (result !== true) {

View File

@ -1,4 +1,4 @@
'use strict';
'use strict'
import TransactionBase from './TransactionBase.js'
import Base58 from '../deps/Base58.js'
import { store } from '../../api.js'

View File

@ -2,7 +2,6 @@ import nacl from '../../deps/nacl-fast.js'
import utils from '../../deps/utils.js'
import Base58 from '../../deps/Base58.js'
const signArbitrary = (arbitraryBytesBase58, arbitraryBytesForSigningBase58, nonce, keyPair) => {
if (!arbitraryBytesBase58) {
@ -18,11 +17,11 @@ const signArbitrary = (arbitraryBytesBase58, arbitraryBytesForSigningBase58, non
}
const arbitraryBytes = Base58.decode(arbitraryBytesBase58)
const _arbitraryBytesBuffer = Object.keys(arbitraryBytes).map(function (key) { return arbitraryBytes[key]; });
const _arbitraryBytesBuffer = Object.keys(arbitraryBytes).map(function (key) { return arbitraryBytes[key]; })
const arbitraryBytesBuffer = new Uint8Array(_arbitraryBytesBuffer)
const arbitraryBytesForSigning = Base58.decode(arbitraryBytesForSigningBase58)
const _arbitraryBytesForSigningBuffer = Object.keys(arbitraryBytesForSigning).map(function (key) { return arbitraryBytesForSigning[key]; });
const _arbitraryBytesForSigningBuffer = Object.keys(arbitraryBytesForSigning).map(function (key) { return arbitraryBytesForSigning[key]; })
const arbitraryBytesForSigningBuffer = new Uint8Array(_arbitraryBytesForSigningBuffer)
const _nonce = utils.int32ToBytes(nonce)

View File

@ -1,42 +1,37 @@
"use strict";
/*
TO DO
*/
'use strict'
(function () {
function generateSignatureArbitraryTransactionV3(keyPair, lastReference, service, arbitraryData, fee, timestamp) => {
const data = generateArbitraryTransactionV3Base(keyPair.publicKey, lastReference, service, arbitraryData, fee, timestamp);
return nacl.sign.detached(data, keyPair.privateKey);
const data = generateArbitraryTransactionV3Base(keyPair.publicKey, lastReference, service, arbitraryData, fee, timestamp)
return nacl.sign.detached(data, keyPair.privateKey)
}
function generateArbitraryTransactionV3(keyPair, lastReference, service, arbitraryData, fee, timestamp, signature) => {
return appendBuffer(generateArbitraryTransactionV3Base(keyPair.publicKey, lastReference, service, arbitraryData, fee, timestamp),
signature);
return appendBuffer(generateArbitraryTransactionV3Base(keyPair.publicKey, lastReference, service, arbitraryData, fee, timestamp), signature)
}
function generateArbitraryTransactionV3Base(publicKey, lastReference, service, arbitraryData, fee, timestamp) => {
const txType = TYPES.ARBITRARY_TRANSACTION;
const typeBytes = int32ToBytes(txType);
const timestampBytes = int64ToBytes(timestamp);
const feeBytes = int64ToBytes(fee * 100000000);
const serviceBytes = int32ToBytes(service);
const dataSizeBytes = int32ToBytes(arbitraryData.length);
const paymentsLengthBytes = int32ToBytes(0); // Support payments - not yet.
const txType = TYPES.ARBITRARY_TRANSACTION
const typeBytes = int32ToBytes(txType)
const timestampBytes = int64ToBytes(timestamp)
const feeBytes = int64ToBytes(fee * 100000000)
const serviceBytes = int32ToBytes(service)
const dataSizeBytes = int32ToBytes(arbitraryData.length)
const paymentsLengthBytes = int32ToBytes(0) // Support payments - not yet.
var data = new Uint8Array();
var data = new Uint8Array()
data = appendBuffer(data, typeBytes);
data = appendBuffer(data, timestampBytes);
data = appendBuffer(data, lastReference);
data = appendBuffer(data, publicKey);
data = appendBuffer(data, paymentsLengthBytes);
data = appendBuffer(data, typeBytes)
data = appendBuffer(data, timestampBytes)
data = appendBuffer(data, lastReference)
data = appendBuffer(data, publicKey)
data = appendBuffer(data, paymentsLengthBytes)
// Here it is necessary to insert the payments, if there are
data = appendBuffer(data, serviceBytes);
data = appendBuffer(data, dataSizeBytes);
data = appendBuffer(data, arbitraryData);
data = appendBuffer(data, feeBytes);
data = appendBuffer(data, serviceBytes)
data = appendBuffer(data, dataSizeBytes)
data = appendBuffer(data, arbitraryData)
data = appendBuffer(data, feeBytes)
return data;
return data
}
}())

View File

@ -1,4 +1,4 @@
'use strict';
'use strict'
import { TX_TYPES, QORT_DECIMALS } from '../../constants.js'
import nacl from '../../deps/nacl-fast.js'
import Base58 from '../../deps/Base58.js'
@ -18,77 +18,38 @@ export default class ChatBase {
constructor() {
this.fee = 0
this.groupID = 0
this.tests = [
() => {
if (!(this._type >= 1 && this._type in TX_TYPES)) {
return 'Invalid type: ' + this.type
}
return true
},
() => {
if (this._fee < 0) {
return 'Invalid fee: ' + this._fee / QORT_DECIMALS
}
return true
},
() => {
if (this._groupID < 0 || !Number.isInteger(this._groupID)) {
return 'Invalid groupID: ' + this._groupID
}
return true
},
() => {
if (!(new Date(this._timestamp)).getTime() > 0) {
return 'Invalid timestamp: ' + this._timestamp
}
return true
},
() => {
if (!(this._lastReference instanceof Uint8Array && this._lastReference.byteLength == 64)) {
return 'Invalid last reference: ' + this._lastReference
}
return true
},
() => {
if (!(this._keyPair)) {
return 'keyPair must be specified'
}
if (!(this._keyPair.publicKey instanceof Uint8Array && this._keyPair.publicKey.byteLength === 32)) {
return 'Invalid publicKey'
}
if (!(this._keyPair.privateKey instanceof Uint8Array && this._keyPair.privateKey.byteLength === 64)) {
return 'Invalid privateKey'
}
return true
}
]
}
set keyPair(keyPair) {
this._keyPair = keyPair
}
set type(type) {
this.typeText = TX_TYPES[type]
this._type = type
this._typeBytes = this.constructor.utils.int32ToBytes(this._type)
}
set groupID(groupID) {
this._groupID = groupID
this._groupIDBytes = this.constructor.utils.int32ToBytes(this._groupID)
}
set timestamp(timestamp) {
this._timestamp = timestamp
this._timestampBytes = this.constructor.utils.int64ToBytes(this._timestamp)
}
set fee(fee) {
this._fee = fee * QORT_DECIMALS
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee)
}
set lastReference(lastReference) {
this._lastReference = lastReference instanceof Uint8Array ? lastReference : this.constructor.Base58.decode(lastReference)
}
get params() {
get params() {
return [
this._typeBytes,
this._timestampBytes,
@ -99,7 +60,6 @@ export default class ChatBase {
}
get chatBytes() {
const isValid = this.validParams()
if (!isValid.valid) {
throw new Error(isValid.message)

View File

@ -1,13 +1,14 @@
"use strict";
'use strict'
import ChatBase from "./ChatBase.js"
import nacl from '../../deps/nacl-fast.js'
import ed2curve from '../../deps/ed2curve.js'
import { Sha256 } from 'asmcrypto.js'
import { CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP } from '../../constants.js'
export default class ChatTransaction extends ChatBase {
constructor() {
super();
super()
this.type = 18
this.fee = 0
}
@ -15,37 +16,42 @@ export default class ChatTransaction extends ChatBase {
set recipientPublicKey(recipientPublicKey) {
this._base58RecipientPublicKey = recipientPublicKey instanceof Uint8Array ? this.constructor.Base58.encode(recipientPublicKey) : recipientPublicKey
this._recipientPublicKey = this.constructor.Base58.decode(this._base58RecipientPublicKey)
}
set proofOfWorkNonce(proofOfWorkNonce) {
this._proofOfWorkNonce = this.constructor.utils.int32ToBytes(proofOfWorkNonce)
}
set recipient(recipient) {
this._recipient = recipient instanceof Uint8Array ? recipient : this.constructor.Base58.decode(recipient)
this._hasReceipient = new Uint8Array(1)
this._hasReceipient[0] = 1
}
set hasChatReference(hasChatReference) {
this._hasChatReference = new Uint8Array(1)
this._hasChatReference[0] = hasChatReference
}
set chatReference(chatReference) {
this._chatReference = chatReference instanceof Uint8Array ? chatReference : this.constructor.Base58.decode(chatReference)
}
set message(message) {
this.messageText = message;
this._message = this.constructor.utils.stringtoUTF8Array(message)
this._messageLength = this.constructor.utils.int32ToBytes(this._message.length)
}
set isEncrypted(isEncrypted) {
this._isEncrypted = new Uint8Array(1);
this._isEncrypted[0] = isEncrypted;
this._isEncrypted = new Uint8Array(1)
this._isEncrypted[0] = isEncrypted
if (isEncrypted === 1) {
const convertedPrivateKey = ed2curve.convertSecretKey(this._keyPair.privateKey)
const convertedPublicKey = ed2curve.convertPublicKey(this._recipientPublicKey)
const sharedSecret = new Uint8Array(32);
nacl.lowlevel.crypto_scalarmult(sharedSecret, convertedPrivateKey, convertedPublicKey);
const sharedSecret = new Uint8Array(32)
nacl.lowlevel.crypto_scalarmult(sharedSecret, convertedPrivateKey, convertedPublicKey)
this._chatEncryptionSeed = new Sha256().process(sharedSecret).finish().result
this._encryptedMessage = nacl.secretbox(this._message, this._lastReference.slice(0, 24), this._chatEncryptionSeed)
@ -56,8 +62,8 @@ export default class ChatTransaction extends ChatBase {
}
set isText(isText) {
this._isText = new Uint8Array(1);
this._isText[0] = isText;
this._isText = new Uint8Array(1)
this._isText[0] = isText
}
get params() {
@ -72,6 +78,15 @@ export default class ChatTransaction extends ChatBase {
this._isText,
this._feeBytes
)
return params;
// After the feature trigger timestamp we need to include chat reference
if (new Date(this._timestamp).getTime() >= CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP) {
params.push(this._hasChatReference)
if (this._hasChatReference[0] == 1) {
params.push(this._chatReference)
}
}
return params
}
}

View File

@ -1,4 +1,4 @@
"use strict";
'use strict'
import ChatBase from "./ChatBase.js"
export default class GroupChatTransaction extends ChatBase {
@ -12,28 +12,34 @@ export default class GroupChatTransaction extends ChatBase {
this._proofOfWorkNonce = this.constructor.utils.int32ToBytes(proofOfWorkNonce)
}
set hasReceipient(hasReceipient) {
this._hasReceipient = new Uint8Array(1)
this._hasReceipient[0] = hasReceipient
}
set message(message) {
this.messageText = message;
this.messageText = message
this._message = this.constructor.utils.stringtoUTF8Array(message)
this._messageLength = this.constructor.utils.int32ToBytes(this._message.length)
}
set hasChatReference(hasChatReference) {
this._hasChatReference = new Uint8Array(1)
this._hasChatReference[0] = hasChatReference
}
set chatReference(chatReference) {
this._chatReference = chatReference instanceof Uint8Array ? chatReference : this.constructor.Base58.decode(chatReference)
}
set isEncrypted(isEncrypted) {
this._isEncrypted = new Uint8Array(1);
this._isEncrypted[0] = isEncrypted; // Set to false...
this._isEncrypted[0] = isEncrypted
}
set isText(isText) {
this._isText = new Uint8Array(1);
this._isText[0] = isText; // Set to true
this._isText = new Uint8Array(1)
this._isText[0] = isText
}
get params() {
@ -47,6 +53,15 @@ export default class GroupChatTransaction extends ChatBase {
this._isText,
this._feeBytes
)
return params;
// After the feature trigger timestamp we need to include chat reference
if (new Date(this._timestamp).getTime() >= CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP) {
params.push(this._hasChatReference)
if (this._hasChatReference[0] == 1) {
params.push(this._chatReference)
}
}
return params
}
}

View File

@ -3,7 +3,6 @@ import Base58 from '../../deps/Base58.js'
import ed2curve from '../../deps/ed2curve.js'
import { Sha256 } from 'asmcrypto.js'
export const decryptChatMessage = (encryptedMessage, privateKey, recipientPublicKey, lastReference) => {
let _encryptedMessage = Base58.decode(encryptedMessage)
@ -15,13 +14,13 @@ export const decryptChatMessage = (encryptedMessage, privateKey, recipientPublic
const convertedPrivateKey = ed2curve.convertSecretKey(privateKey)
const convertedPublicKey = ed2curve.convertPublicKey(_recipientPublicKey)
const sharedSecret = new Uint8Array(32);
nacl.lowlevel.crypto_scalarmult(sharedSecret, convertedPrivateKey, convertedPublicKey);
nacl.lowlevel.crypto_scalarmult(sharedSecret, convertedPrivateKey, convertedPublicKey)
const _chatEncryptionSeed = new Sha256().process(sharedSecret).finish().result
const _decryptedMessage = nacl.secretbox.open(_encryptedMessage, _lastReference.slice(0, 24), _chatEncryptionSeed)
let decryptedMessage = ''
_decryptedMessage === false ? decryptedMessage : decryptedMessage = new TextDecoder('utf-8').decode(_decryptedMessage);
_decryptedMessage === false ? decryptedMessage : decryptedMessage = new TextDecoder('utf-8').decode(_decryptedMessage)
return decryptedMessage
}

View File

@ -1,7 +1,6 @@
import nacl from '../../deps/nacl-fast.js'
import utils from '../../deps/utils.js'
const signChat = (chatBytes, nonce, keyPair) => {
if (!chatBytes) {
@ -19,12 +18,11 @@ const signChat = (chatBytes, nonce, keyPair) => {
const _nonce = utils.int32ToBytes(nonce)
if (chatBytes.length === undefined) {
const _chatBytesBuffer = Object.keys(chatBytes).map(function (key) { return chatBytes[key]; });
const _chatBytesBuffer = Object.keys(chatBytes).map(function (key) { return chatBytes[key]; })
const chatBytesBuffer = new Uint8Array(_chatBytesBuffer)
chatBytesBuffer.set(_nonce, 112)
const signature = nacl.sign.detached(chatBytesBuffer, keyPair.privateKey)
const signedBytes = utils.appendBuffer(chatBytesBuffer, signature)
@ -34,7 +32,6 @@ const signChat = (chatBytes, nonce, keyPair) => {
const chatBytesBuffer = new Uint8Array(chatBytes)
chatBytesBuffer.set(_nonce, 112)
const signature = nacl.sign.detached(chatBytesBuffer, keyPair.privateKey)
const signedBytes = utils.appendBuffer(chatBytesBuffer, signature)

View File

@ -1,6 +1,6 @@
'use strict';
import TransactionBase from "../TransactionBase.js"
import { QORT_DECIMALS } from "../../constants.js"
'use strict'
import TransactionBase from '../TransactionBase.js'
import { QORT_DECIMALS } from '../../constants.js'
export default class AddGroupAdminTransaction extends TransactionBase {
constructor() {
@ -27,7 +27,7 @@ export default class AddGroupAdminTransaction extends TransactionBase {
}
set rGroupId(rGroupId) {
this._rGroupId = rGroupId;
this._rGroupId = rGroupId
this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._rGroupId)
}

View File

@ -1,6 +1,6 @@
'use strict';
import TransactionBase from "../TransactionBase.js"
import { QORT_DECIMALS } from "../../constants.js"
'use strict'
import TransactionBase from '../TransactionBase.js'
import { QORT_DECIMALS } from '../../constants.js'
export default class CancelGroupBanTransaction extends TransactionBase {
constructor() {

View File

@ -1,6 +1,6 @@
'use strict';
import TransactionBase from "../TransactionBase.js"
import { QORT_DECIMALS } from "../../constants.js"
'use strict'
import TransactionBase from '../TransactionBase.js'
import { QORT_DECIMALS } from '../../constants.js'
export default class CancelGroupInviteTransaction extends TransactionBase {
constructor() {
@ -34,7 +34,7 @@ export default class CancelGroupInviteTransaction extends TransactionBase {
}
set rGroupId(rGroupId) {
this._rGroupId = rGroupId;
this._rGroupId = rGroupId
this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._rGroupId)
}

View File

@ -1,6 +1,6 @@
"use strict";
import TransactionBase from "../TransactionBase.js"
import { QORT_DECIMALS } from "../../constants.js"
'use strict'
import TransactionBase from '../TransactionBase.js'
import { QORT_DECIMALS } from '../../constants.js'
export default class CreateGroupTransaction extends TransactionBase {
constructor() {
@ -48,40 +48,40 @@ export default class CreateGroupTransaction extends TransactionBase {
}
set rGroupName(rGroupName) {
this._rGroupName = rGroupName;
this._rGroupName = rGroupName
this._rGroupNameBytes = this.constructor.utils.stringtoUTF8Array(this._rGroupName.toLocaleLowerCase())
this._rGroupNameLength = this.constructor.utils.int32ToBytes(this._rGroupNameBytes.length)
}
set rGroupDesc(rGroupDesc) {
this._rGroupDesc = rGroupDesc;
this._rGroupDesc = rGroupDesc
this._rGroupDescBytes = this.constructor.utils.stringtoUTF8Array(this._rGroupDesc.toLocaleLowerCase())
this._rGroupDescLength = this.constructor.utils.int32ToBytes(this._rGroupDescBytes.length)
}
set rGroupType(rGroupType) {
this.myGroupType = rGroupType;
this.myGroupType = rGroupType
this._rGroupType = new Uint8Array(1)
this._rGroupType[0] = rGroupType;
this._rGroupType[0] = rGroupType
}
set rGroupApprovalThreshold(rGroupApprovalThreshold) {
this._rGroupApprovalThreshold = new Uint8Array(1)
this._rGroupApprovalThreshold[0] = rGroupApprovalThreshold;
this._rGroupApprovalThreshold[0] = rGroupApprovalThreshold
}
set rGroupMinimumBlockDelay(rGroupMinimumBlockDelay) {
this._rGroupMinimumBlockDelay = rGroupMinimumBlockDelay;
this._rGroupMinimumBlockDelay = rGroupMinimumBlockDelay
this._rGroupMinimumBlockDelayBytes = this.constructor.utils.int32ToBytes(this._rGroupMinimumBlockDelay)
}
set rGroupMaximumBlockDelay(rGroupMaximumBlockDelay) {
this._rGroupMaximumBlockDelay = rGroupMaximumBlockDelay;
this._rGroupMaximumBlockDelay = rGroupMaximumBlockDelay
this._rGroupMaximumBlockDelayBytes = this.constructor.utils.int32ToBytes(this._rGroupMaximumBlockDelay)
}
get params() {
const params = super.params;
const params = super.params
params.push(
this._rGroupNameLength,
this._rGroupNameBytes,
@ -93,6 +93,6 @@ export default class CreateGroupTransaction extends TransactionBase {
this._rGroupMaximumBlockDelayBytes,
this._feeBytes
)
return params;
return params
}
}

View File

@ -1,6 +1,6 @@
'use strict';
import TransactionBase from "../TransactionBase.js"
import { QORT_DECIMALS } from "../../constants.js"
'use strict'
import TransactionBase from '../TransactionBase.js'
import { QORT_DECIMALS } from '../../constants.js'
export default class GroupBanTransaction extends TransactionBase {
constructor() {
@ -27,7 +27,7 @@ export default class GroupBanTransaction extends TransactionBase {
}
set rGroupId(rGroupId) {
this._rGroupId = rGroupId;
this._rGroupId = rGroupId
this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._rGroupId)
}

View File

@ -1,6 +1,6 @@
'use strict';
import TransactionBase from "../TransactionBase.js"
import { QORT_DECIMALS } from "../../constants.js"
'use strict'
import TransactionBase from '../TransactionBase.js'
import { QORT_DECIMALS } from '../../constants.js'
export default class GroupInviteTransaction extends TransactionBase {
constructor() {
@ -27,7 +27,7 @@ export default class GroupInviteTransaction extends TransactionBase {
}
set rGroupId(rGroupId) {
this._rGroupId = rGroupId;
this._rGroupId = rGroupId
this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._rGroupId)
}

View File

@ -1,6 +1,6 @@
'use strict';
import TransactionBase from "../TransactionBase.js"
import { QORT_DECIMALS } from "../../constants.js"
'use strict'
import TransactionBase from '../TransactionBase.js'
import { QORT_DECIMALS } from '../../constants.js'
export default class GroupKickTransaction extends TransactionBase {
constructor() {
@ -27,7 +27,7 @@ export default class GroupKickTransaction extends TransactionBase {
}
set rGroupId(rGroupId) {
this._rGroupId = rGroupId;
this._rGroupId = rGroupId
this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._rGroupId)
}

View File

@ -1,19 +1,11 @@
"use strict";
import TransactionBase from "../TransactionBase.js"
import { QORT_DECIMALS } from "../../constants.js"
'use strict'
import TransactionBase from '../TransactionBase.js'
import { QORT_DECIMALS } from '../../constants.js'
export default class JoinGroupTransaction extends TransactionBase {
constructor() {
super()
this.type = 31
this.tests.push(
() => {
if (!(this._registrantAddress instanceof Uint8Array && this._registrantAddress.length == 25)) {
return "Invalid Registrant " + Base58.encode(this._registrantAddress)
}
return true
}
)
}
render(html) {
@ -39,25 +31,25 @@ export default class JoinGroupTransaction extends TransactionBase {
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee)
}
set registrantAddress(registrantAddress) {// Always Base58 encoded. Accepts Uint8Array or Base58 string.
this._registrantAddress = registrantAddress instanceof Uint8Array ? registrantAddress : this.constructor.Base58.decode(registrantAddress);
set registrantAddress(registrantAddress) {
this._registrantAddress = registrantAddress instanceof Uint8Array ? registrantAddress : this.constructor.Base58.decode(registrantAddress)
}
set rGroupId(rGroupId) {
this._rGroupId = rGroupId;
this._rGroupId = rGroupId
this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._rGroupId)
}
set rGroupName(rGroupName) {
this._rGroupName = rGroupName;
this._rGroupName = rGroupName
}
get params() {
const params = super.params;
const params = super.params
params.push(
this._rGroupIdBytes,
this._feeBytes
)
return params;
return params
}
}

View File

@ -1,19 +1,11 @@
"use strict";
import TransactionBase from "../TransactionBase.js"
import { QORT_DECIMALS } from "../../constants.js"
'use strict'
import TransactionBase from '../TransactionBase.js'
import { QORT_DECIMALS } from '../../constants.js'
export default class LeaveGroupTransaction extends TransactionBase {
constructor() {
super()
this.type = 32
this.tests.push(
() => {
if (!(this._registrantAddress instanceof Uint8Array && this._registrantAddress.length == 25)) {
return "Invalid Registrant " + Base58.encode(this._registrantAddress)
}
return true
}
)
}
render(html) {
@ -39,25 +31,25 @@ export default class LeaveGroupTransaction extends TransactionBase {
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee)
}
set registrantAddress(registrantAddress) {// Always Base58 encoded. Accepts Uint8Array or Base58 string.
this._registrantAddress = registrantAddress instanceof Uint8Array ? registrantAddress : this.constructor.Base58.decode(registrantAddress);
set registrantAddress(registrantAddress) {
this._registrantAddress = registrantAddress instanceof Uint8Array ? registrantAddress : this.constructor.Base58.decode(registrantAddress)
}
set rGroupId(rGroupId) {
this._rGroupId = rGroupId;
this._rGroupId = rGroupId
this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._rGroupId)
}
set rGroupName(rGroupName) {
this._rGroupName = rGroupName;
this._rGroupName = rGroupName
}
get params() {
const params = super.params;
const params = super.params
params.push(
this._rGroupIdBytes,
this._feeBytes
)
return params;
return params
}
}

View File

@ -1,6 +1,6 @@
'use strict';
import TransactionBase from "../TransactionBase.js"
import { QORT_DECIMALS } from "../../constants.js"
'use strict'
import TransactionBase from '../TransactionBase.js'
import { QORT_DECIMALS } from '../../constants.js'
export default class RemoveGroupAdminTransaction extends TransactionBase {
constructor() {
@ -27,7 +27,7 @@ export default class RemoveGroupAdminTransaction extends TransactionBase {
}
set rGroupId(rGroupId) {
this._rGroupId = rGroupId;
this._rGroupId = rGroupId
this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._rGroupId)
}

View File

@ -1,4 +1,4 @@
'use strict';
'use strict'
import TransactionBase from '../TransactionBase.js'
import { QORT_DECIMALS } from '../../constants.js'

View File

@ -1,4 +1,4 @@
'use strict';
'use strict'
import TransactionBase from '../TransactionBase.js'
import { QORT_DECIMALS } from '../../constants.js'

View File

@ -1,6 +1,6 @@
"use strict";
import TransactionBase from "../TransactionBase.js"
import { QORT_DECIMALS } from "../../constants.js"
'use strict'
import TransactionBase from '../TransactionBase.js'
import { QORT_DECIMALS } from '../../constants.js'
export default class RegisterNameTransaction extends TransactionBase {
constructor() {
@ -32,19 +32,19 @@ export default class RegisterNameTransaction extends TransactionBase {
}
set name(name) {
this.nameText = name;
this.nameText = name
this._nameBytes = this.constructor.utils.stringtoUTF8Array(name)
this._nameLength = this.constructor.utils.int32ToBytes(this._nameBytes.length)
}
set value(value) {
this.valueText = value.length === 0 ? "Registered Name on the Qortal Chain" : value;
this.valueText = value.length === 0 ? "Registered Name on the Qortal Chain" : value
this._valueBytes = this.constructor.utils.stringtoUTF8Array(this.valueText)
this._valueLength = this.constructor.utils.int32ToBytes(this._valueBytes.length)
}
get params() {
const params = super.params;
const params = super.params
params.push(
this._nameLength,
this._nameBytes,
@ -52,6 +52,6 @@ export default class RegisterNameTransaction extends TransactionBase {
this._valueBytes,
this._feeBytes
)
return params;
return params
}
}

View File

@ -1,4 +1,4 @@
'use strict';
'use strict'
import TransactionBase from '../TransactionBase.js'
import { QORT_DECIMALS } from '../../constants.js'

View File

@ -1,39 +1,36 @@
"use strict";
/*
TO DO
*/
'use strict'
(function () {
function generateSignatureRegisterNameTransaction(keyPair, lastReference, owner, name, value, fee, timestamp) => {
const data = generateRegisterNameTransactionBase(keyPair.publicKey, lastReference, owner, name, value, fee, timestamp);
return nacl.sign.detached(data, keyPair.privateKey);
const data = generateRegisterNameTransactionBase(keyPair.publicKey, lastReference, owner, name, value, fee, timestamp)
return nacl.sign.detached(data, keyPair.privateKey)
}
function generateRegisterNameTransaction(keyPair, lastReference, owner, name, value, fee, timestamp, signature) => {
return appendBuffer( generateRegisterNameTransactionBase(keyPair.publicKey, lastReference, owner, name, value, fee, timestamp),
signature );
return appendBuffer(generateRegisterNameTransactionBase(keyPair.publicKey, lastReference, owner, name, value, fee, timestamp), signature)
}
function generateRegisterNameTransactionBase(publicKey, lastReference, owner, name, value, fee, timestamp) => {
const txType = TYPES.REGISTER_NAME_TRANSACTION;
const typeBytes = int32ToBytes(txType);
const timestampBytes = int64ToBytes(timestamp);
const feeBytes = int64ToBytes(fee * 100000000);
const nameSizeBytes = int32ToBytes(name.length);
const valueSizeBytes = int32ToBytes(value.length);
const txType = TYPES.REGISTER_NAME_TRANSACTION
const typeBytes = int32ToBytes(txType)
const timestampBytes = int64ToBytes(timestamp)
const feeBytes = int64ToBytes(fee * 100000000)
const nameSizeBytes = int32ToBytes(name.length)
const valueSizeBytes = int32ToBytes(value.length)
let data = new Uint8Array();
let data = new Uint8Array()
data = appendBuffer(data, typeBytes);
data = appendBuffer(data, timestampBytes);
data = appendBuffer(data, lastReference);
data = appendBuffer(data, publicKey);
data = appendBuffer(data, owner);
data = appendBuffer(data, nameSizeBytes);
data = appendBuffer(data, name);
data = appendBuffer(data, valueSizeBytes);
data = appendBuffer(data, value);
data = appendBuffer(data, feeBytes);
data = appendBuffer(data, typeBytes)
data = appendBuffer(data, timestampBytes)
data = appendBuffer(data, lastReference)
data = appendBuffer(data, publicKey)
data = appendBuffer(data, owner)
data = appendBuffer(data, nameSizeBytes)
data = appendBuffer(data, name)
data = appendBuffer(data, valueSizeBytes)
data = appendBuffer(data, value)
data = appendBuffer(data, feeBytes)
return data;
return data
}
}())

View File

@ -1,7 +1,7 @@
"use strict";
import TransactionBase from "../TransactionBase.js"
'use strict'
import TransactionBase from '../TransactionBase.js'
import publicKeyToAddress from '../../wallet/publicKeyToAddress.js'
import { Base58 } from "../../deps/deps.js";
import { Base58 } from '../../deps/deps.js'
export default class RemoveRewardShareTransaction extends TransactionBase {
constructor() {
@ -20,11 +20,11 @@ export default class RemoveRewardShareTransaction extends TransactionBase {
}
set rewarddialog5(rewarddialog5) {
this._rewarddialog5 = rewarddialog5;
this._rewarddialog5 = rewarddialog5
}
set rewarddialog6(rewarddialog6) {
this._rewarddialog6 = rewarddialog6;
this._rewarddialog6 = rewarddialog6
}
set rewardShareKeyPairPublicKey(rewardShareKeyPairPublicKey) {
@ -50,6 +50,6 @@ export default class RemoveRewardShareTransaction extends TransactionBase {
this._percentageShareBytes,
this._feeBytes
)
return params;
return params
}
}

View File

@ -1,4 +1,4 @@
"use strict";
'use strict'
import publicKeyToAddress from '../../wallet/publicKeyToAddress.js'
import TransactionBase from "../TransactionBase.js"
import nacl from '../../deps/nacl-fast.js'
@ -23,19 +23,19 @@ export default class RewardShareTransaction extends TransactionBase {
}
set rewarddialog1(rewarddialog1) {
this._rewarddialog1 = rewarddialog1;
this._rewarddialog1 = rewarddialog1
}
set rewarddialog2(rewarddialog2) {
this._rewarddialog2 = rewarddialog2;
this._rewarddialog2 = rewarddialog2
}
set rewarddialog3(rewarddialog3) {
this._rewarddialog3 = rewarddialog3;
this._rewarddialog3 = rewarddialog3
}
set rewarddialog4(rewarddialog4) {
this._rewarddialog4 = rewarddialog4;
this._rewarddialog4 = rewarddialog4
}
set recipientPublicKey(recipientPublicKey) {
@ -46,7 +46,6 @@ export default class RewardShareTransaction extends TransactionBase {
this.fee = (recipientPublicKey === this.constructor.Base58.encode(this._keyPair.publicKey) ? 0 : 0.001)
// Reward share keys
const convertedPrivateKey = ed2curve.convertSecretKey(this._keyPair.privateKey)
const convertedPublicKey = ed2curve.convertPublicKey(this._recipientPublicKey)
const sharedSecret = new Uint8Array(32);
@ -57,7 +56,7 @@ export default class RewardShareTransaction extends TransactionBase {
this._rewardShareKeyPair = nacl.sign.keyPair.fromSeed(this._rewardShareSeed)
}
set recipient(recipient) { // Always Base58 encoded. Accepts Uint8Array or Base58 string.
set recipient(recipient) {
this._recipient = recipient instanceof Uint8Array ? recipient : this.constructor.Base58.decode(recipient)
}
@ -74,6 +73,6 @@ export default class RewardShareTransaction extends TransactionBase {
this._percentageShareBytes,
this._feeBytes
)
return params;
return params
}
}

View File

@ -10,62 +10,46 @@ export default class TradeBotCreateRequest {
}
createTransaction(txnReq) {
this.creatorPublicKey(txnReq.creatorPublicKey)
this.qortAmount(txnReq.qortAmount)
this.fundingQortAmount(txnReq.fundingQortAmount)
this.foreignBlockchain(txnReq.foreignBlockchain)
this.foreignAmount(txnReq.foreignAmount)
this.tradeTimeout(txnReq.tradeTimeout)
this.receivingAddress(txnReq.receivingAddress)
this.creatorPublicKey(txnReq.creatorPublicKey);
this.qortAmount(txnReq.qortAmount);
this.fundingQortAmount(txnReq.fundingQortAmount);
this.foreignBlockchain(txnReq.foreignBlockchain);
this.foreignAmount(txnReq.foreignAmount);
this.tradeTimeout(txnReq.tradeTimeout);
this.receivingAddress(txnReq.receivingAddress);
return this.txnRequest();
return this.txnRequest()
}
creatorPublicKey(creatorPublicKey) {
this._creatorPublicKey = creatorPublicKey;
this._creatorPublicKey = creatorPublicKey
}
qortAmount(qortAmount) {
this._qortAmount = qortAmount;
this._qortAmount = qortAmount
}
fundingQortAmount(fundingQortAmount) {
this._fundingQortAmount = fundingQortAmount;
this._fundingQortAmount = fundingQortAmount
}
foreignBlockchain(foreignBlockchain) {
this._foreignBlockchain = foreignBlockchain;
this._foreignBlockchain = foreignBlockchain
}
foreignAmount(foreignAmount) {
this._foreignAmount = foreignAmount;
this._foreignAmount = foreignAmount
}
tradeTimeout(tradeTimeout) {
this._tradeTimeout = tradeTimeout;
this._tradeTimeout = tradeTimeout
}
receivingAddress(receivingAddress) {
this._receivingAddress = receivingAddress;
this._receivingAddress = receivingAddress
}
txnRequest() {
return {
creatorPublicKey: this._creatorPublicKey,
qortAmount: this._qortAmount,

View File

@ -10,18 +10,14 @@ export default class TradeBotRespondRequest {
}
createTransaction(txnReq) {
this.atAddress(txnReq.atAddress)
this.foreignKey(txnReq.foreignKey)
this.receivingAddress(txnReq.receivingAddress)
return this.txnRequest()
}
atAddress(atAddress) {
this._atAddress = atAddress
}
@ -30,12 +26,10 @@ export default class TradeBotRespondRequest {
}
receivingAddress(receivingAddress) {
this._receivingAddress = receivingAddress
}
txnRequest() {
return {
atAddress: this._atAddress,
foreignKey: this._foreignKey,

View File

@ -2,9 +2,7 @@ import Base58 from '../../../deps/Base58.js'
import nacl from '../../../deps/nacl-fast.js'
import utils from '../../../deps/utils.js'
const signTradeBotTransaction = (unsignedTxn, keyPair) => {
if (!unsignedTxn) {
throw new Error('Unsigned Transaction Bytes not defined')
}
@ -16,19 +14,14 @@ const signTradeBotTransaction = (unsignedTxn, keyPair) => {
const txnBuffer = Base58.decode(unsignedTxn)
if (keyPair.privateKey.length === undefined) {
const _privateKey = Object.keys(keyPair.privateKey).map(function (key) { return keyPair.privateKey[key]; });
const _privateKey = Object.keys(keyPair.privateKey).map(function (key) { return keyPair.privateKey[key]; })
const privateKey = new Uint8Array(_privateKey)
const signature = nacl.sign.detached(txnBuffer, privateKey)
const signedBytes = utils.appendBuffer(txnBuffer, signature)
return signedBytes
} else {
const signature = nacl.sign.detached(txnBuffer, keyPair.privateKey)
const signedBytes = utils.appendBuffer(txnBuffer, signature)
return signedBytes

View File

@ -10,27 +10,21 @@ export default class DeleteTradeOffer {
}
createTransaction(txnReq) {
this.creatorPublicKey(txnReq.creatorPublicKey)
this.atAddress(txnReq.atAddress)
return this.txnRequest()
}
creatorPublicKey(creatorPublicKey) {
this._creatorPublicKey = creatorPublicKey
}
atAddress(atAddress) {
this._atAddress = atAddress
}
txnRequest() {
return {
creatorPublicKey: this._creatorPublicKey,
atAddress: this._atAddress

View File

@ -1,24 +1,25 @@
import { request } from '../../../fetch-request.js'
import { deleteTradeOffer, signTradeBotTxn } from '../../../tradeRequest.js';
import { deleteTradeOffer, signTradeBotTxn } from '../../../tradeRequest.js'
import { processTransaction } from '../../../createTransaction.js'
export const cancelAllOffers = async (requestObject) => {
const keyPair = requestObject.keyPair;
const publicKey = requestObject.base58PublicKey;
const address = requestObject.address;
const keyPair = requestObject.keyPair
const publicKey = requestObject.base58PublicKey
const address = requestObject.address
const getMyOpenOffers = async () => {
const res = await request('/crosschain/tradeoffers');
const myOpenTradeOrders = await res.filter(order => order.mode === "OFFERING" && order.qortalCreator === address);
return myOpenTradeOrders;
const res = await request('/crosschain/tradeoffers')
const myOpenTradeOrders = await res.filter(order => order.mode === "OFFERING" && order.qortalCreator === address)
return myOpenTradeOrders
}
const myOpenOffers = await getMyOpenOffers();
let response = true;
const myOpenOffers = await getMyOpenOffers()
let response = true
myOpenOffers.forEach(async (openOffer) => {
let unsignedTxn = await deleteTradeOffer({ creatorPublicKey: publicKey, atAddress: openOffer.qortalAtAddress });
let signedTxnBytes = await signTradeBotTxn(unsignedTxn, keyPair);
await processTransaction(signedTxnBytes);
});
let unsignedTxn = await deleteTradeOffer({ creatorPublicKey: publicKey, atAddress: openOffer.qortalAtAddress })
let signedTxnBytes = await signTradeBotTxn(unsignedTxn, keyPair)
await processTransaction(signedTxnBytes)
})
return response
}

View File

@ -1,11 +1,8 @@
import publicKeyToAddress from './publicKeyToAddress'
import Base58 from '../deps/Base58.js'
export const base58PublicKeyToAddress = (base58pubkey, qora = false) => {
const decodePubKey = Base58.decode(base58pubkey)
const address = publicKeyToAddress(decodePubKey, qora)
return address
}

View File

@ -1,12 +1,10 @@
import RIPEMD160 from '../deps/ripemd160.js'
import BROKEN_RIPEMD160 from '../deps/broken-ripemd160.js'
import { Sha256 } from 'asmcrypto.js'
import utils from '../deps/utils.js'
import Base58 from '../deps/Base58.js'
import { Buffer } from 'buffer'
import BROKEN_RIPEMD160 from '../deps/broken-ripemd160.js'
import RIPEMD160 from '../deps/ripemd160.js'
import utils from '../deps/utils.js'
import { ADDRESS_VERSION } from '../constants.js'
import { Buffer } from 'buffer'
import { Sha256 } from 'asmcrypto.js'
const repeatSHA256 = (passphrase, hashes) => {
let hash = passphrase
@ -19,8 +17,8 @@ const repeatSHA256 = (passphrase, hashes) => {
const publicKeyToAddress = (publicKey, qora = false) => {
const publicKeySha256 = new Sha256().process(publicKey).finish().result
const _publicKeyHash = qora ? new BROKEN_RIPEMD160().digest(publicKeySha256) : new RIPEMD160().update(Buffer.from(publicKeySha256)).digest('hex')
const publicKeyHash = qora ? _publicKeyHash : _publicKeyHash
let address = new Uint8Array()
address = utils.appendBuffer(address, [ADDRESS_VERSION])

View File

@ -1,6 +1,5 @@
import Base58 from '../deps/Base58.js'
export const validateAddress = (address) => {
const decodePubKey = Base58.decode(address)
@ -8,5 +7,4 @@ export const validateAddress = (address) => {
return false
}
return true
}

View File

@ -6,7 +6,7 @@ const configWatchers = []
const waitingForConfig = []
const subscribeToStore = () => {
if (!store) return setTimeout(() => subscribeToStore(), 50) // 0.05s
if (!store) return setTimeout(() => subscribeToStore(), 50)
store.subscribe(() => {
const cA = store.getState().app
@ -25,7 +25,6 @@ export function getConfig() {
}
export function watchConfig(fn) {
// config ? fn(config) : void 0
fn(config)
configWatchers.push(fn)
}

View File

@ -183,6 +183,7 @@ class ChatModals extends LitElement {
timestamp: sendTimestamp,
recipient: recipient,
recipientPublicKey: _publicKey,
hasChatReference: 0,
message: messageText,
lastReference: reference,
proofOfWorkNonce: 0,

View File

@ -695,6 +695,7 @@ class ChatPage extends LitElement {
timestamp: Date.now(),
recipient: this._chatId,
recipientPublicKey: this._publicKey.key,
hasChatReference: 0,
message: messageText,
lastReference: reference,
proofOfWorkNonce: 0,
@ -712,6 +713,7 @@ class ChatPage extends LitElement {
timestamp: Date.now(),
groupID: Number(this._chatId),
hasReceipient: 0,
hasChatReference: 0,
message: messageText,
lastReference: reference,
proofOfWorkNonce: 0,

View File

@ -410,6 +410,7 @@ class ChatWelcomePage extends LitElement {
timestamp: sendTimestamp,
recipient: recipient,
recipientPublicKey: _publicKey,
hasChatReference: 0,
message: messageText,
lastReference: reference,
proofOfWorkNonce: 0,

View File

@ -529,6 +529,7 @@ class NameMenu extends LitElement {
timestamp: sendTimestamp,
recipient: recipient,
recipientPublicKey: _publicKey,
hasChatReference: 0,
message: messageText,
lastReference: reference,
proofOfWorkNonce: 0,

View File

@ -789,6 +789,7 @@ class Chat extends LitElement {
timestamp: sendTimestamp,
recipient: recipient,
recipientPublicKey: _publicKey,
hasChatReference: 0,
message: messageText,
lastReference: reference,
proofOfWorkNonce: 0,