Remove use strict make api full esm compatible

This commit is contained in:
AlphaX-Projects
2024-05-10 18:00:47 +02:00
parent 3cc5d544a2
commit 0b2bceb842
64 changed files with 9391 additions and 9472 deletions

View File

@@ -1,5 +1,5 @@
import TransactionBase from './TransactionBase'
import {QORT_DECIMALS} from '../constants'
import { QORT_DECIMALS } from '../constants'
export default class PaymentTransaction extends TransactionBase {
constructor() {

View File

@@ -1,6 +1,6 @@
import TransactionBase from './TransactionBase'
import {store} from '../../api'
import {QORT_DECIMALS} from '../constants'
import { store } from '../../api'
import { QORT_DECIMALS } from '../constants'
export default class DeployAtTransaction extends TransactionBase {
constructor() {

View File

@@ -1,6 +1,6 @@
import TransactionBase from './TransactionBase'
import Base58 from '../deps/Base58'
import {store} from '../../api'
import { store } from '../../api'
export default class PaymentTransaction extends TransactionBase {
constructor() {

View File

@@ -1,5 +1,5 @@
import ChatBase from './chat/ChatBase'
import {QORT_DECIMALS} from '../constants'
import { QORT_DECIMALS } from '../constants'
export default class PublicizeTransaction extends ChatBase {
constructor() {
@@ -8,21 +8,21 @@ export default class PublicizeTransaction extends ChatBase {
this.fee = 0
}
set proofOfWorkNonce(proofOfWorkNonce) {
this._proofOfWorkNonce = this.constructor.utils.int32ToBytes(proofOfWorkNonce)
}
set proofOfWorkNonce(proofOfWorkNonce) {
this._proofOfWorkNonce = this.constructor.utils.int32ToBytes(proofOfWorkNonce)
}
set fee(fee) {
this._fee = fee * QORT_DECIMALS
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee)
}
set fee(fee) {
this._fee = fee * QORT_DECIMALS
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee)
}
get params() {
const params = super.params
params.push(
this._proofOfWorkNonce,
this._feeBytes
)
return params
}
get params() {
const params = super.params
params.push(
this._proofOfWorkNonce,
this._feeBytes
)
return params
}
}

View File

@@ -1,4 +1,4 @@
import {QORT_DECIMALS, TX_TYPES} from '../constants'
import { QORT_DECIMALS, TX_TYPES } from '../constants'
import nacl from '../deps/nacl-fast'
import Base58 from '../deps/Base58'
import utils from '../deps/utils'

View File

@@ -1,6 +1,6 @@
import TransactionBase from './TransactionBase'
import {store} from '../../api'
import {QORT_DECIMALS} from '../constants'
import { store } from '../../api'
import { QORT_DECIMALS } from '../constants'
export default class TransferPrivsTransaction extends TransactionBase {
constructor() {

View File

@@ -1,38 +1,36 @@
'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)
}
(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)
}
function generateArbitraryTransactionV3(keyPair, lastReference, service, arbitraryData, fee, timestamp, signature) => {
return appendBuffer(generateArbitraryTransactionV3Base(keyPair.publicKey, lastReference, service, arbitraryData, fee, timestamp), signature)
}
function generateArbitraryTransactionV3(keyPair, 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.
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.
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)
// 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)
return data
}
}())
return data
}
}())

View File

@@ -1,143 +1,143 @@
import {QORT_DECIMALS, TX_TYPES} from '../../constants'
import { QORT_DECIMALS, TX_TYPES } from '../../constants'
import nacl from '../../deps/nacl-fast'
import Base58 from '../../deps/Base58'
import utils from '../../deps/utils'
export default class ChatBase {
static get utils() {
return utils
}
static get utils() {
return utils
}
static get nacl() {
return nacl
}
static get nacl() {
return nacl
}
static get Base58() {
return Base58
}
static get Base58() {
return Base58
}
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
}
]
}
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 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 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 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 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 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)
}
set lastReference(lastReference) {
this._lastReference = lastReference instanceof Uint8Array ? lastReference : this.constructor.Base58.decode(lastReference)
}
get params() {
return [
this._typeBytes,
this._timestampBytes,
this._groupIDBytes,
this._lastReference,
this._keyPair.publicKey
]
}
get params() {
return [
this._typeBytes,
this._timestampBytes,
this._groupIDBytes,
this._lastReference,
this._keyPair.publicKey
]
}
get chatBytes() {
const isValid = this.validParams()
if (!isValid.valid) {
throw new Error(isValid.message)
}
get chatBytes() {
const isValid = this.validParams()
if (!isValid.valid) {
throw new Error(isValid.message)
}
let result = new Uint8Array()
let result = new Uint8Array()
this.params.forEach(item => {
result = this.constructor.utils.appendBuffer(result, item)
})
this.params.forEach(item => {
result = this.constructor.utils.appendBuffer(result, item)
})
this._chatBytes = result
this._chatBytes = result
return this._chatBytes
}
return this._chatBytes
}
validParams() {
let finalResult = {
valid: true
}
validParams() {
let finalResult = {
valid: true
}
this.tests.some(test => {
const result = test()
if (result !== true) {
finalResult = {
valid: false,
message: result
}
return true
}
})
this.tests.some(test => {
const result = test()
if (result !== true) {
finalResult = {
valid: false,
message: result
}
return true
}
})
return finalResult
}
return finalResult
}
}

View File

@@ -1,8 +1,8 @@
import ChatBase from './ChatBase'
import nacl from '../../deps/nacl-fast'
import ed2curve from '../../deps/ed2curve'
import {Sha256} from 'asmcrypto.js'
import {CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP} from '../../constants'
import { Sha256 } from 'asmcrypto.js'
import { CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP } from '../../constants'
export default class ChatTransaction extends ChatBase {
constructor() {

View File

@@ -1,5 +1,5 @@
import ChatBase from './ChatBase'
import {CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP} from '../../constants'
import { CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP } from '../../constants'
export default class GroupChatTransaction extends ChatBase {
constructor() {

View File

@@ -1,7 +1,7 @@
import nacl from '../../deps/nacl-fast'
import Base58 from '../../deps/Base58'
import ed2curve from '../../deps/ed2curve'
import {Sha256} from 'asmcrypto.js'
import { Sha256 } from 'asmcrypto.js'
export const decryptChatMessage = (encryptedMessage, privateKey, recipientPublicKey, lastReference) => {
let _encryptedMessage = Base58.decode(encryptedMessage)

View File

@@ -1,5 +1,5 @@
import TransactionBase from '../TransactionBase'
import {QORT_DECIMALS} from '../../constants'
import { QORT_DECIMALS } from '../../constants'
export default class AddGroupAdminTransaction extends TransactionBase {
constructor() {

View File

@@ -1,5 +1,5 @@
import TransactionBase from '../TransactionBase'
import {QORT_DECIMALS} from '../../constants'
import { QORT_DECIMALS } from '../../constants'
export default class CancelGroupBanTransaction extends TransactionBase {
constructor() {

View File

@@ -1,5 +1,5 @@
import TransactionBase from '../TransactionBase'
import {QORT_DECIMALS} from '../../constants'
import { QORT_DECIMALS } from '../../constants'
export default class CancelGroupInviteTransaction extends TransactionBase {
constructor() {

View File

@@ -1,5 +1,5 @@
import TransactionBase from '../TransactionBase'
import {QORT_DECIMALS} from '../../constants'
import { QORT_DECIMALS } from '../../constants'
export default class CreateGroupTransaction extends TransactionBase {
constructor() {

View File

@@ -1,5 +1,5 @@
import TransactionBase from '../TransactionBase'
import {QORT_DECIMALS} from '../../constants'
import { QORT_DECIMALS } from '../../constants'
export default class GroupBanTransaction extends TransactionBase {
constructor() {

View File

@@ -1,5 +1,5 @@
import TransactionBase from '../TransactionBase'
import {QORT_DECIMALS} from '../../constants'
import { QORT_DECIMALS } from '../../constants'
export default class GroupInviteTransaction extends TransactionBase {
constructor() {

View File

@@ -1,5 +1,5 @@
import TransactionBase from '../TransactionBase'
import {QORT_DECIMALS} from '../../constants'
import { QORT_DECIMALS } from '../../constants'
export default class GroupKickTransaction extends TransactionBase {
constructor() {

View File

@@ -1,5 +1,5 @@
import TransactionBase from '../TransactionBase'
import {QORT_DECIMALS} from '../../constants'
import { QORT_DECIMALS } from '../../constants'
export default class JoinGroupTransaction extends TransactionBase {
constructor() {

View File

@@ -1,5 +1,5 @@
import TransactionBase from '../TransactionBase'
import {QORT_DECIMALS} from '../../constants'
import { QORT_DECIMALS } from '../../constants'
export default class LeaveGroupTransaction extends TransactionBase {
constructor() {

View File

@@ -1,5 +1,5 @@
import TransactionBase from '../TransactionBase'
import {QORT_DECIMALS} from '../../constants'
import { QORT_DECIMALS } from '../../constants'
export default class RemoveGroupAdminTransaction extends TransactionBase {
constructor() {

View File

@@ -1,5 +1,5 @@
import TransactionBase from '../TransactionBase'
import {QORT_DECIMALS} from '../../constants'
import { QORT_DECIMALS } from '../../constants'
export default class UpdateGroupTransaction extends TransactionBase {
constructor() {

View File

@@ -1,5 +1,5 @@
import TransactionBase from '../TransactionBase'
import {QORT_DECIMALS} from '../../constants'
import { QORT_DECIMALS } from '../../constants'
export default class BuyNameTransacion extends TransactionBase {
constructor() {

View File

@@ -1,5 +1,5 @@
import TransactionBase from '../TransactionBase'
import {QORT_DECIMALS} from '../../constants'
import { QORT_DECIMALS } from '../../constants'
export default class CancelSellNameTransacion extends TransactionBase {
constructor() {

View File

@@ -1,5 +1,5 @@
import TransactionBase from '../TransactionBase'
import {QORT_DECIMALS} from '../../constants'
import { QORT_DECIMALS } from '../../constants'
export default class RegisterNameTransaction extends TransactionBase {
constructor() {

View File

@@ -1,5 +1,5 @@
import TransactionBase from '../TransactionBase'
import {QORT_DECIMALS} from '../../constants'
import { QORT_DECIMALS } from '../../constants'
export default class SellNameTransacion extends TransactionBase {
constructor() {

View File

@@ -1,5 +1,5 @@
import TransactionBase from '../TransactionBase'
import {QORT_DECIMALS} from '../../constants'
import { QORT_DECIMALS } from '../../constants'
export default class UpdateNameTransaction extends TransactionBase {
constructor() {

View File

@@ -1,5 +1,5 @@
import TransactionBase from '../TransactionBase'
import {QORT_DECIMALS} from '../../constants'
import { QORT_DECIMALS } from '../../constants'
export default class CreatePollTransaction extends TransactionBase {
constructor() {
@@ -35,7 +35,7 @@ export default class CreatePollTransaction extends TransactionBase {
this._options.push({ length: optionLength, bytes: optionBytes })
}
set feeDialog(feeDialog){
set feeDialog(feeDialog) {
this._feeDialog = feeDialog
}
@@ -106,7 +106,7 @@ export default class CreatePollTransaction extends TransactionBase {
params.push(this._options[i].length, this._options[i].bytes)
}
params.push(this._feeBytes);
params.push(this._feeBytes)
return params
}

View File

@@ -1,5 +1,5 @@
import TransactionBase from '../TransactionBase'
import {QORT_DECIMALS} from '../../constants'
import { QORT_DECIMALS } from '../../constants'
export default class VoteOnPollTransaction extends TransactionBase {
constructor() {
@@ -20,7 +20,7 @@ export default class VoteOnPollTransaction extends TransactionBase {
`
}
set feeDialog(feeDialog){
set feeDialog(feeDialog) {
this._feeDialog = feeDialog
}

View File

@@ -1,36 +1,34 @@
'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)
}
(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)
}
function generateRegisterNameTransaction(keyPair, lastReference, owner, name, value, fee, timestamp, signature) => {
return appendBuffer(generateRegisterNameTransactionBase(keyPair.publicKey, lastReference, owner, name, value, fee, timestamp), signature)
}
function generateRegisterNameTransaction(keyPair, 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)
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)
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 @@
import TransactionBase from '../TransactionBase'
import publicKeyToAddress from '../../wallet/publicKeyToAddress'
import {Base58} from '../../deps/deps'
import {DYNAMIC_FEE_TIMESTAMP} from '../../constants'
import { Base58 } from '../../deps/deps'
import { DYNAMIC_FEE_TIMESTAMP } from '../../constants'
export default class RemoveRewardShareTransaction extends TransactionBase {
constructor() {

View File

@@ -2,8 +2,8 @@ import publicKeyToAddress from '../../wallet/publicKeyToAddress'
import TransactionBase from '../TransactionBase'
import nacl from '../../deps/nacl-fast'
import ed2curve from '../../deps/ed2curve'
import {Sha256} from 'asmcrypto.js'
import {DYNAMIC_FEE_TIMESTAMP} from '../../constants'
import { Sha256 } from 'asmcrypto.js'
import { DYNAMIC_FEE_TIMESTAMP } from '../../constants'
export default class RewardShareTransaction extends TransactionBase {
constructor() {