Organize code (prettier)

This commit is contained in:
Nicola Benaglia 2025-05-16 23:54:59 +02:00
parent 55f8ea9843
commit b0274b4cb7
44 changed files with 3020 additions and 2795 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,175 +1,186 @@
// Qortal TX types // Qortal TX types
const TX_TYPES = { const TX_TYPES = {
1: "Genesis", 1: 'Genesis',
2: "Payment", 2: 'Payment',
3: "Name registration", 3: 'Name registration',
4: "Name update", 4: 'Name update',
5: "Sell name", 5: 'Sell name',
6: "Cancel sell name", 6: 'Cancel sell name',
7: "Buy name", 7: 'Buy name',
8: "Create poll", 8: 'Create poll',
9: "Vote in poll", 9: 'Vote in poll',
10: "Arbitrary", 10: 'Arbitrary',
11: "Issue asset", 11: 'Issue asset',
12: "Transfer asset", 12: 'Transfer asset',
13: "Create asset order", 13: 'Create asset order',
14: "Cancel asset order", 14: 'Cancel asset order',
15: "Multi-payment transaction", 15: 'Multi-payment transaction',
16: "Deploy AT", 16: 'Deploy AT',
17: "Message", 17: 'Message',
18: "Chat", 18: 'Chat',
19: "Publicize", 19: 'Publicize',
20: "Airdrop", 20: 'Airdrop',
21: "AT", 21: 'AT',
22: "Create group", 22: 'Create group',
23: "Update group", 23: 'Update group',
24: "Add group admin", 24: 'Add group admin',
25: "Remove group admin", 25: 'Remove group admin',
26: "Group ban", 26: 'Group ban',
27: "Cancel group ban", 27: 'Cancel group ban',
28: "Group kick", 28: 'Group kick',
29: "Group invite", 29: 'Group invite',
30: "Cancel group invite", 30: 'Cancel group invite',
31: "Join group", 31: 'Join group',
32: "Leave group", 32: 'Leave group',
33: "Group approval", 33: 'Group approval',
34: "Set group", 34: 'Set group',
35: "Update asset", 35: 'Update asset',
36: "Account flags", 36: 'Account flags',
37: "Enable forging", 37: 'Enable forging',
38: "Reward share", 38: 'Reward share',
39: "Account level", 39: 'Account level',
40: "Transfer privs", 40: 'Transfer privs',
41: "Presence" 41: 'Presence',
} };
// Qortal error codes // Qortal error codes
const ERROR_CODES = { const ERROR_CODES = {
1: "Valid OK", 1: 'Valid OK',
2: "Invalid address", 2: 'Invalid address',
3: "Negative amount", 3: 'Negative amount',
4: "Nagative fee", 4: 'Nagative fee',
5: "No balance", 5: 'No balance',
6: "Invalid reference", 6: 'Invalid reference',
7: "Invalid time length", 7: 'Invalid time length',
8: "Invalid value length", 8: 'Invalid value length',
9: "Name already registered", 9: 'Name already registered',
10: "Name does not exist", 10: 'Name does not exist',
11: "Invalid name owner", 11: 'Invalid name owner',
12: "Name already for sale", 12: 'Name already for sale',
13: "Name not for sale", 13: 'Name not for sale',
14: "Name buyer already owner", 14: 'Name buyer already owner',
15: "Invalid amount", 15: 'Invalid amount',
16: "Invalid seller", 16: 'Invalid seller',
17: "Name not lowercase", 17: 'Name not lowercase',
18: "Invalid description length", 18: 'Invalid description length',
19: "Invalid options length", 19: 'Invalid options length',
20: "Invalid option length", 20: 'Invalid option length',
21: "Duplicate option", 21: 'Duplicate option',
22: "Poll already created", 22: 'Poll already created',
23: "Poll already has votes", 23: 'Poll already has votes',
24: "Poll does not exist", 24: 'Poll does not exist',
25: "Option does not exist", 25: 'Option does not exist',
26: "Already voted for that option", 26: 'Already voted for that option',
27: "Invalid data length", 27: 'Invalid data length',
28: "Invalid quantity", 28: 'Invalid quantity',
29: "Asset does not exist", 29: 'Asset does not exist',
30: "Invalid return", 30: 'Invalid return',
31: "Have equals want", 31: 'Have equals want',
32: "Order does not exist", 32: 'Order does not exist',
33: "Invalid order creator", 33: 'Invalid order creator',
34: "Invalid payments length", 34: 'Invalid payments length',
35: "Negative price", 35: 'Negative price',
36: "Invalid creation bytes", 36: 'Invalid creation bytes',
37: "Invalid tags length", 37: 'Invalid tags length',
38: "Invalid type length", 38: 'Invalid type length',
39: "Invalid AT transaction", 39: 'Invalid AT transaction',
40: "Insufficient fee", 40: 'Insufficient fee',
41: "Asset does not match AT", 41: 'Asset does not match AT',
43: "Asset already exists", 43: 'Asset already exists',
44: "Missing creator", 44: 'Missing creator',
45: "Timestamp too old", 45: 'Timestamp too old',
46: "Timestamp too new", 46: 'Timestamp too new',
47: "Too many unconfirmed", 47: 'Too many unconfirmed',
48: "Group already exists", 48: 'Group already exists',
49: "Group does not exist", 49: 'Group does not exist',
50: "Invalid group owner", 50: 'Invalid group owner',
51: "Already group memeber", 51: 'Already group memeber',
52: "Group owner can not leave", 52: 'Group owner can not leave',
53: "Not group member", 53: 'Not group member',
54: "Already group admin", 54: 'Already group admin',
55: "Not group admin", 55: 'Not group admin',
56: "Invalid lifetime", 56: 'Invalid lifetime',
57: "Invite unknown", 57: 'Invite unknown',
58: "Ban exists", 58: 'Ban exists',
59: "Ban unknown", 59: 'Ban unknown',
60: "Banned from group", 60: 'Banned from group',
61: "Join request", 61: 'Join request',
62: "Invalid group approval threshold", 62: 'Invalid group approval threshold',
63: "Group ID mismatch", 63: 'Group ID mismatch',
64: "Invalid group ID", 64: 'Invalid group ID',
65: "Transaction unknown", 65: 'Transaction unknown',
66: "Transaction already confirmed", 66: 'Transaction already confirmed',
67: "Invalid TX group", 67: 'Invalid TX group',
68: "TX group ID mismatch", 68: 'TX group ID mismatch',
69: "Multiple names forbidden", 69: 'Multiple names forbidden',
70: "Invalid asset owner", 70: 'Invalid asset owner',
71: "AT is finished", 71: 'AT is finished',
72: "No flag permission", 72: 'No flag permission',
73: "Not minting accout", 73: 'Not minting accout',
77: "Invalid rewardshare percent", 77: 'Invalid rewardshare percent',
78: "Public key unknown", 78: 'Public key unknown',
79: "Invalid public key", 79: 'Invalid public key',
80: "AT unknown", 80: 'AT unknown',
81: "AT already exists", 81: 'AT already exists',
82: "Group approval not required", 82: 'Group approval not required',
83: "Group approval decided", 83: 'Group approval decided',
84: "Maximum reward shares", 84: 'Maximum reward shares',
85: "Transaction already exists", 85: 'Transaction already exists',
86: "No blockchain lock", 86: 'No blockchain lock',
87: "Order already closed", 87: 'Order already closed',
88: "Clock not synced", 88: 'Clock not synced',
89: "Asset not spendable", 89: 'Asset not spendable',
90: "Account can not reward share", 90: 'Account can not reward share',
91: "Self share exists", 91: 'Self share exists',
92: "Account already exists", 92: 'Account already exists',
93: "Invalid group block delay", 93: 'Invalid group block delay',
94: "Incorrect nonce", 94: 'Incorrect nonce',
95: "Ivalid timestamp signature", 95: 'Ivalid timestamp signature',
96: "Address blocked", 96: 'Address blocked',
97: "Name Blocked", 97: 'Name Blocked',
98: "Group approval required", 98: 'Group approval required',
99: "Account not transferable", 99: 'Account not transferable',
999: "Ivalid but ok", 999: 'Ivalid but ok',
1000: "Not yet released." 1000: 'Not yet released.',
} };
// Qortal 8 decimals // Qortal 8 decimals
const QORT_DECIMALS = 1e8 const QORT_DECIMALS = 1e8;
// Q for Qortal // Q for Qortal
const ADDRESS_VERSION = 58 const ADDRESS_VERSION = 58;
// Proxy for api calls // Proxy for api calls
const PROXY_URL = "/proxy/" const PROXY_URL = '/proxy/';
// Chat reference timestamp // Chat reference timestamp
const CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP = 1674316800000 const CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP = 1674316800000;
// Dynamic fee timestamp // Dynamic fee timestamp
const DYNAMIC_FEE_TIMESTAMP = 1692118800000 const DYNAMIC_FEE_TIMESTAMP = 1692118800000;
// Used as a salt for all Qora addresses. Salts used for storing your private keys in local storage will be randomly generated // 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 STATIC_SALT = new Uint8Array([
const BCRYPT_ROUNDS = 10 // Remember that the total work spent on key derivation is BCRYPT_ROUNDS * KDF_THREADS 54, 190, 201, 206, 65, 29, 123, 129, 147, 231, 180, 166, 171, 45, 95, 165, 78,
const BCRYPT_VERSION = "2a" 200, 208, 194, 44, 207, 221, 146, 45, 238, 68, 68, 69, 102, 62, 6,
const STATIC_BCRYPT_SALT = `$${BCRYPT_VERSION}$${BCRYPT_ROUNDS}$IxVE941tXVUD4cW0TNVm.O` ]);
const KDF_THREADS = 16 const BCRYPT_ROUNDS = 10; // Remember that the total work spent on key derivation is BCRYPT_ROUNDS * KDF_THREADS
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, CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP, DYNAMIC_FEE_TIMESTAMP } export {
TX_TYPES,
ERROR_CODES,
QORT_DECIMALS,
PROXY_URL,
STATIC_SALT,
ADDRESS_VERSION,
KDF_THREADS,
STATIC_BCRYPT_SALT,
CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP,
DYNAMIC_FEE_TIMESTAMP,
};

View File

@ -1,37 +1,35 @@
// @ts-nocheck // @ts-nocheck
import { QORT_DECIMALS } from "../constants/constants" import { QORT_DECIMALS } from '../constants/constants';
import TransactionBase from "./TransactionBase" import TransactionBase from './TransactionBase';
export default class AddGroupAdminTransaction extends TransactionBase { export default class AddGroupAdminTransaction extends TransactionBase {
constructor() { constructor() {
super() super();
this.type = 24 this.type = 24;
} }
set rGroupId(rGroupId) { set rGroupId(rGroupId) {
this._rGroupId = rGroupId this._rGroupId = rGroupId;
this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._rGroupId) this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._rGroupId);
} }
set recipient(recipient) { set recipient(recipient) {
this._recipient = recipient instanceof Uint8Array ? recipient : this.constructor.Base58.decode(recipient) this._recipient =
this.theRecipient = recipient recipient instanceof Uint8Array
? recipient
: this.constructor.Base58.decode(recipient);
this.theRecipient = recipient;
} }
set fee(fee) { set fee(fee) {
this._fee = fee * QORT_DECIMALS this._fee = fee * QORT_DECIMALS;
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee) this._feeBytes = this.constructor.utils.int64ToBytes(this._fee);
} }
get params() { get params() {
const params = super.params const params = super.params;
params.push( params.push(this._rGroupIdBytes, this._recipient, this._feeBytes);
this._rGroupIdBytes, return params;
this._recipient,
this._feeBytes
)
return params
} }
} }

View File

@ -1,45 +1,48 @@
// @ts-nocheck // @ts-nocheck
import { QORT_DECIMALS } from "../constants/constants" import { QORT_DECIMALS } from '../constants/constants';
import TransactionBase from "./TransactionBase" import TransactionBase from './TransactionBase';
export default class BuyNameTransacion extends TransactionBase { export default class BuyNameTransacion extends TransactionBase {
constructor() { constructor() {
super() super();
this.type = 7 this.type = 7;
} }
set fee(fee) { set fee(fee) {
this._fee = fee * QORT_DECIMALS this._fee = fee * QORT_DECIMALS;
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee) this._feeBytes = this.constructor.utils.int64ToBytes(this._fee);
} }
set name(name) { set name(name) {
this.nameText = name this.nameText = name;
this._nameBytes = this.constructor.utils.stringtoUTF8Array(name) this._nameBytes = this.constructor.utils.stringtoUTF8Array(name);
this._nameLength = this.constructor.utils.int32ToBytes(this._nameBytes.length) this._nameLength = this.constructor.utils.int32ToBytes(
this._nameBytes.length
);
} }
set sellPrice(sellPrice) { set sellPrice(sellPrice) {
this._sellPrice = sellPrice * QORT_DECIMALS this._sellPrice = sellPrice * QORT_DECIMALS;
this._sellPriceBytes = this.constructor.utils.int64ToBytes(this._sellPrice) this._sellPriceBytes = this.constructor.utils.int64ToBytes(this._sellPrice);
} }
set recipient(recipient) { set recipient(recipient) {
this._recipient = recipient instanceof Uint8Array ? recipient : this.constructor.Base58.decode(recipient) this._recipient =
this.theRecipient = recipient recipient instanceof Uint8Array
? recipient
: this.constructor.Base58.decode(recipient);
this.theRecipient = recipient;
} }
get params() { get params() {
const params = super.params const params = super.params;
params.push( params.push(
this._nameLength, this._nameLength,
this._nameBytes, this._nameBytes,
this._sellPriceBytes, this._sellPriceBytes,
this._recipient, this._recipient,
this._feeBytes this._feeBytes
) );
return params return params;
} }
} }

View File

@ -1,37 +1,35 @@
// @ts-nocheck // @ts-nocheck
import { QORT_DECIMALS } from "../constants/constants" import { QORT_DECIMALS } from '../constants/constants';
import TransactionBase from "./TransactionBase" import TransactionBase from './TransactionBase';
export default class CancelGroupBanTransaction extends TransactionBase { export default class CancelGroupBanTransaction extends TransactionBase {
constructor() { constructor() {
super() super();
this.type = 27 this.type = 27;
} }
set rGroupId(rGroupId) { set rGroupId(rGroupId) {
this._rGroupId = rGroupId this._rGroupId = rGroupId;
this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._rGroupId) this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._rGroupId);
} }
set recipient(recipient) { set recipient(recipient) {
this._recipient = recipient instanceof Uint8Array ? recipient : this.constructor.Base58.decode(recipient) this._recipient =
this.theRecipient = recipient recipient instanceof Uint8Array
? recipient
: this.constructor.Base58.decode(recipient);
this.theRecipient = recipient;
} }
set fee(fee) { set fee(fee) {
this._fee = fee * QORT_DECIMALS this._fee = fee * QORT_DECIMALS;
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee) this._feeBytes = this.constructor.utils.int64ToBytes(this._fee);
} }
get params() { get params() {
const params = super.params const params = super.params;
params.push( params.push(this._rGroupIdBytes, this._recipient, this._feeBytes);
this._rGroupIdBytes, return params;
this._recipient,
this._feeBytes
)
return params
} }
} }

View File

@ -1,36 +1,33 @@
// @ts-nocheck // @ts-nocheck
import { QORT_DECIMALS } from "../constants/constants" import { QORT_DECIMALS } from '../constants/constants';
import TransactionBase from "./TransactionBase" import TransactionBase from './TransactionBase';
export default class CancelGroupInviteTransaction extends TransactionBase { export default class CancelGroupInviteTransaction extends TransactionBase {
constructor() { constructor() {
super() super();
this.type = 30 this.type = 30;
} }
set rGroupId(rGroupId) { set rGroupId(rGroupId) {
this._rGroupId = rGroupId this._rGroupId = rGroupId;
this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._rGroupId) this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._rGroupId);
} }
set recipient(recipient) { set recipient(recipient) {
this._recipient = recipient instanceof Uint8Array ? recipient : this.constructor.Base58.decode(recipient) this._recipient =
this.theRecipient = recipient recipient instanceof Uint8Array
? recipient
: this.constructor.Base58.decode(recipient);
this.theRecipient = recipient;
} }
set fee(fee) { set fee(fee) {
this._fee = fee * QORT_DECIMALS this._fee = fee * QORT_DECIMALS;
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee) this._feeBytes = this.constructor.utils.int64ToBytes(this._fee);
} }
get params() { get params() {
const params = super.params const params = super.params;
params.push( params.push(this._rGroupIdBytes, this._recipient, this._feeBytes);
this._rGroupIdBytes, return params;
this._recipient,
this._feeBytes
)
return params
} }
} }

View File

@ -1,33 +1,29 @@
// @ts-nocheck // @ts-nocheck
import { QORT_DECIMALS } from "../constants/constants" import { QORT_DECIMALS } from '../constants/constants';
import TransactionBase from "./TransactionBase" import TransactionBase from './TransactionBase';
export default class CancelSellNameTransacion extends TransactionBase { export default class CancelSellNameTransacion extends TransactionBase {
constructor() { constructor() {
super() super();
this.type = 6 this.type = 6;
} }
set fee(fee) { set fee(fee) {
this._fee = fee * QORT_DECIMALS this._fee = fee * QORT_DECIMALS;
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee) this._feeBytes = this.constructor.utils.int64ToBytes(this._fee);
} }
set name(name) { set name(name) {
this.nameText = name this.nameText = name;
this._nameBytes = this.constructor.utils.stringtoUTF8Array(name) this._nameBytes = this.constructor.utils.stringtoUTF8Array(name);
this._nameLength = this.constructor.utils.int32ToBytes(this._nameBytes.length) this._nameLength = this.constructor.utils.int32ToBytes(
this._nameBytes.length
);
} }
get params() { get params() {
const params = super.params const params = super.params;
params.push( params.push(this._nameLength, this._nameBytes, this._feeBytes);
this._nameLength, return params;
this._nameBytes,
this._feeBytes
)
return params
} }
} }

View File

@ -1,102 +1,116 @@
// @ts-nocheck // @ts-nocheck
import { QORT_DECIMALS, TX_TYPES } from '../constants/constants' import { QORT_DECIMALS, TX_TYPES } from '../constants/constants';
import nacl from '../deps/nacl-fast' import nacl from '../deps/nacl-fast';
import Base58 from '../deps/Base58' import Base58 from '../deps/Base58';
import utils from '../utils/utils' import utils from '../utils/utils';
export default class ChatBase { export default class ChatBase {
static get utils() { static get utils() {
return utils return utils;
} }
static get nacl() { static get nacl() {
return nacl return nacl;
} }
static get Base58() { static get Base58() {
return Base58 return Base58;
} }
constructor() { constructor() {
this.fee = 0;
this.fee = 0 this.groupID = 0;
this.groupID = 0
this.tests = [ this.tests = [
() => { () => {
if (!(this._type >= 1 && this._type in TX_TYPES)) { if (!(this._type >= 1 && this._type in TX_TYPES)) {
return 'Invalid type: ' + this.type return 'Invalid type: ' + this.type;
} }
return true return true;
}, },
() => { () => {
if (this._fee < 0) { if (this._fee < 0) {
return 'Invalid fee: ' + this._fee / QORT_DECIMALS return 'Invalid fee: ' + this._fee / QORT_DECIMALS;
} }
return true return true;
}, },
() => { () => {
if (this._groupID < 0 || !Number.isInteger(this._groupID)) { if (this._groupID < 0 || !Number.isInteger(this._groupID)) {
return 'Invalid groupID: ' + this._groupID return 'Invalid groupID: ' + this._groupID;
} }
return true return true;
}, },
() => { () => {
if (!(new Date(this._timestamp)).getTime() > 0) { if (!new Date(this._timestamp).getTime() > 0) {
return 'Invalid timestamp: ' + this._timestamp return 'Invalid timestamp: ' + this._timestamp;
} }
return true return true;
}, },
() => { () => {
if (
if (!(this._lastReference instanceof Uint8Array && this._lastReference.byteLength == 64)) { !(
return 'Invalid last reference: ' + this._lastReference this._lastReference instanceof Uint8Array &&
this._lastReference.byteLength == 64
)
) {
return 'Invalid last reference: ' + this._lastReference;
} }
return true return true;
}, },
() => { () => {
if (!(this._keyPair)) { if (!this._keyPair) {
return 'keyPair must be specified' return 'keyPair must be specified';
} }
if (!(this._keyPair.publicKey instanceof Uint8Array && this._keyPair.publicKey.byteLength === 32)) { if (
return 'Invalid publicKey' !(
this._keyPair.publicKey instanceof Uint8Array &&
this._keyPair.publicKey.byteLength === 32
)
) {
return 'Invalid publicKey';
} }
if (!(this._keyPair.privateKey instanceof Uint8Array && this._keyPair.privateKey.byteLength === 64)) { if (
return 'Invalid privateKey' !(
this._keyPair.privateKey instanceof Uint8Array &&
this._keyPair.privateKey.byteLength === 64
)
) {
return 'Invalid privateKey';
} }
return true return true;
} },
] ];
} }
set keyPair(keyPair) { set keyPair(keyPair) {
this._keyPair = keyPair this._keyPair = keyPair;
} }
set type(type) { set type(type) {
this.typeText = TX_TYPES[type] this.typeText = TX_TYPES[type];
this._type = type this._type = type;
this._typeBytes = this.constructor.utils.int32ToBytes(this._type) this._typeBytes = this.constructor.utils.int32ToBytes(this._type);
} }
set groupID(groupID) { set groupID(groupID) {
this._groupID = groupID this._groupID = groupID;
this._groupIDBytes = this.constructor.utils.int32ToBytes(this._groupID) this._groupIDBytes = this.constructor.utils.int32ToBytes(this._groupID);
} }
set timestamp(timestamp) { set timestamp(timestamp) {
this._timestamp = timestamp this._timestamp = timestamp;
this._timestampBytes = this.constructor.utils.int64ToBytes(this._timestamp) this._timestampBytes = this.constructor.utils.int64ToBytes(this._timestamp);
} }
set fee(fee) { set fee(fee) {
this._fee = fee * QORT_DECIMALS this._fee = fee * QORT_DECIMALS;
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee) this._feeBytes = this.constructor.utils.int64ToBytes(this._fee);
} }
set lastReference(lastReference) { set lastReference(lastReference) {
this._lastReference =
this._lastReference = lastReference instanceof Uint8Array ? lastReference : this.constructor.Base58.decode(lastReference) lastReference instanceof Uint8Array
? lastReference
: this.constructor.Base58.decode(lastReference);
} }
get params() { get params() {
@ -105,44 +119,43 @@ export default class ChatBase {
this._timestampBytes, this._timestampBytes,
this._groupIDBytes, this._groupIDBytes,
this._lastReference, this._lastReference,
this._keyPair.publicKey this._keyPair.publicKey,
] ];
} }
get chatBytes() { get chatBytes() {
const isValid = this.validParams() const isValid = this.validParams();
if (!isValid.valid) { if (!isValid.valid) {
throw new Error(isValid.message) throw new Error(isValid.message);
} }
let result = new Uint8Array() let result = new Uint8Array();
this.params.forEach(item => { this.params.forEach((item) => {
result = this.constructor.utils.appendBuffer(result, item) result = this.constructor.utils.appendBuffer(result, item);
}) });
this._chatBytes = result this._chatBytes = result;
return this._chatBytes return this._chatBytes;
} }
validParams() { validParams() {
let finalResult = { let finalResult = {
valid: true valid: true,
} };
this.tests.some(test => { this.tests.some((test) => {
const result = test() const result = test();
if (result !== true) { if (result !== true) {
finalResult = { finalResult = {
valid: false, valid: false,
message: result message: result,
};
return true;
} }
return true });
}
})
return finalResult return finalResult;
} }
} }

View File

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

View File

@ -1,53 +1,62 @@
// @ts-nocheck // @ts-nocheck
import { QORT_DECIMALS } from "../constants/constants" import { QORT_DECIMALS } from '../constants/constants';
import TransactionBase from "./TransactionBase" import TransactionBase from './TransactionBase';
export default class CreateGroupTransaction extends TransactionBase { export default class CreateGroupTransaction extends TransactionBase {
constructor() { constructor() {
super() super();
this.type = 22 this.type = 22;
} }
set fee(fee) { set fee(fee) {
this._fee = fee * QORT_DECIMALS this._fee = fee * QORT_DECIMALS;
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee) this._feeBytes = this.constructor.utils.int64ToBytes(this._fee);
} }
set rGroupName(rGroupName) { set rGroupName(rGroupName) {
this._rGroupName = rGroupName this._rGroupName = rGroupName;
this._rGroupNameBytes = this.constructor.utils.stringtoUTF8Array(this._rGroupName) this._rGroupNameBytes = this.constructor.utils.stringtoUTF8Array(
this._rGroupNameLength = this.constructor.utils.int32ToBytes(this._rGroupNameBytes.length) this._rGroupName
);
this._rGroupNameLength = this.constructor.utils.int32ToBytes(
this._rGroupNameBytes.length
);
} }
set rGroupDesc(rGroupDesc) { set rGroupDesc(rGroupDesc) {
this._rGroupDesc = rGroupDesc this._rGroupDesc = rGroupDesc;
this._rGroupDescBytes = this.constructor.utils.stringtoUTF8Array(this._rGroupDesc) this._rGroupDescBytes = this.constructor.utils.stringtoUTF8Array(
this._rGroupDescLength = this.constructor.utils.int32ToBytes(this._rGroupDescBytes.length) this._rGroupDesc
);
this._rGroupDescLength = this.constructor.utils.int32ToBytes(
this._rGroupDescBytes.length
);
} }
set rGroupType(rGroupType) { set rGroupType(rGroupType) {
this._rGroupType = new Uint8Array(1) this._rGroupType = new Uint8Array(1);
this._rGroupType[0] = rGroupType this._rGroupType[0] = rGroupType;
} }
set rGroupApprovalThreshold(rGroupApprovalThreshold) { set rGroupApprovalThreshold(rGroupApprovalThreshold) {
this._rGroupApprovalThreshold = new Uint8Array(1) this._rGroupApprovalThreshold = new Uint8Array(1);
this._rGroupApprovalThreshold[0] = rGroupApprovalThreshold this._rGroupApprovalThreshold[0] = rGroupApprovalThreshold;
} }
set rGroupMinimumBlockDelay(rGroupMinimumBlockDelay) { set rGroupMinimumBlockDelay(rGroupMinimumBlockDelay) {
this._rGroupMinimumBlockDelayBytes = this.constructor.utils.int32ToBytes(rGroupMinimumBlockDelay) this._rGroupMinimumBlockDelayBytes = this.constructor.utils.int32ToBytes(
rGroupMinimumBlockDelay
);
} }
set rGroupMaximumBlockDelay(rGroupMaximumBlockDelay) { set rGroupMaximumBlockDelay(rGroupMaximumBlockDelay) {
this._rGroupMaximumBlockDelayBytes = this.constructor.utils.int32ToBytes(rGroupMaximumBlockDelay) this._rGroupMaximumBlockDelayBytes = this.constructor.utils.int32ToBytes(
rGroupMaximumBlockDelay
);
} }
get params() { get params() {
const params = super.params const params = super.params;
params.push( params.push(
this._rGroupNameLength, this._rGroupNameLength,
this._rGroupNameBytes, this._rGroupNameBytes,
@ -58,7 +67,7 @@ export default class CreateGroupTransaction extends TransactionBase {
this._rGroupMinimumBlockDelayBytes, this._rGroupMinimumBlockDelayBytes,
this._rGroupMaximumBlockDelayBytes, this._rGroupMaximumBlockDelayBytes,
this._feeBytes this._feeBytes
) );
return params return params;
} }
} }

View File

@ -1,57 +1,68 @@
// @ts-nocheck // @ts-nocheck
import { QORT_DECIMALS } from '../constants/constants' import { QORT_DECIMALS } from '../constants/constants';
import TransactionBase from './TransactionBase' import TransactionBase from './TransactionBase';
export default class CreatePollTransaction extends TransactionBase { export default class CreatePollTransaction extends TransactionBase {
constructor() { constructor() {
super() super();
this.type = 8 this.type = 8;
this._options = [] this._options = [];
} }
addOption(option) { addOption(option) {
const optionBytes = this.constructor.utils.stringtoUTF8Array(option) const optionBytes = this.constructor.utils.stringtoUTF8Array(option);
const optionLength = this.constructor.utils.int32ToBytes(optionBytes.length) const optionLength = this.constructor.utils.int32ToBytes(
this._options.push({ length: optionLength, bytes: optionBytes }) optionBytes.length
);
this._options.push({ length: optionLength, bytes: optionBytes });
} }
set fee(fee) { set fee(fee) {
this._fee = fee * QORT_DECIMALS this._fee = fee * QORT_DECIMALS;
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee) this._feeBytes = this.constructor.utils.int64ToBytes(this._fee);
} }
set ownerAddress(ownerAddress) { set ownerAddress(ownerAddress) {
this._ownerAddress = ownerAddress instanceof Uint8Array ? ownerAddress : this.constructor.Base58.decode(ownerAddress) this._ownerAddress =
ownerAddress instanceof Uint8Array
? ownerAddress
: this.constructor.Base58.decode(ownerAddress);
} }
set rPollName(rPollName) { set rPollName(rPollName) {
this._rPollName = rPollName this._rPollName = rPollName;
this._rPollNameBytes = this.constructor.utils.stringtoUTF8Array(this._rPollName) this._rPollNameBytes = this.constructor.utils.stringtoUTF8Array(
this._rPollNameLength = this.constructor.utils.int32ToBytes(this._rPollNameBytes.length) this._rPollName
);
this._rPollNameLength = this.constructor.utils.int32ToBytes(
this._rPollNameBytes.length
);
} }
set rPollDesc(rPollDesc) { set rPollDesc(rPollDesc) {
this._rPollDesc = rPollDesc this._rPollDesc = rPollDesc;
this._rPollDescBytes = this.constructor.utils.stringtoUTF8Array(this._rPollDesc) this._rPollDescBytes = this.constructor.utils.stringtoUTF8Array(
this._rPollDescLength = this.constructor.utils.int32ToBytes(this._rPollDescBytes.length) this._rPollDesc
);
this._rPollDescLength = this.constructor.utils.int32ToBytes(
this._rPollDescBytes.length
);
} }
set rOptions(rOptions) { set rOptions(rOptions) {
const optionsArray = rOptions[0].split(', ').map(opt => opt.trim()) const optionsArray = rOptions[0].split(', ').map((opt) => opt.trim());
this._pollOptions = optionsArray this._pollOptions = optionsArray;
for (let i = 0; i < optionsArray.length; i++) { for (let i = 0; i < optionsArray.length; i++) {
this.addOption(optionsArray[i]) this.addOption(optionsArray[i]);
} }
this._rNumberOfOptionsBytes = this.constructor.utils.int32ToBytes(optionsArray.length) this._rNumberOfOptionsBytes = this.constructor.utils.int32ToBytes(
optionsArray.length
);
} }
get params() { get params() {
const params = super.params const params = super.params;
params.push( params.push(
this._ownerAddress, this._ownerAddress,
this._rPollNameLength, this._rPollNameLength,
@ -59,15 +70,15 @@ export default class CreatePollTransaction extends TransactionBase {
this._rPollDescLength, this._rPollDescLength,
this._rPollDescBytes, this._rPollDescBytes,
this._rNumberOfOptionsBytes this._rNumberOfOptionsBytes
) );
// Push the dynamic options // Push the dynamic options
for (let i = 0; i < this._options.length; i++) { for (let i = 0; i < this._options.length; i++) {
params.push(this._options[i].length, this._options[i].bytes) params.push(this._options[i].length, this._options[i].bytes);
} }
params.push(this._feeBytes) params.push(this._feeBytes);
return params return params;
} }
} }

View File

@ -1,63 +1,75 @@
// @ts-nocheck // @ts-nocheck
import TransactionBase from './TransactionBase';
import TransactionBase from './TransactionBase' import { QORT_DECIMALS } from '../constants/constants';
import { QORT_DECIMALS } from '../constants/constants'
export default class DeployAtTransaction extends TransactionBase { export default class DeployAtTransaction extends TransactionBase {
constructor() { constructor() {
super() super();
this.type = 16 this.type = 16;
} }
set fee(fee) { set fee(fee) {
this._fee = fee * QORT_DECIMALS this._fee = fee * QORT_DECIMALS;
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee) this._feeBytes = this.constructor.utils.int64ToBytes(this._fee);
} }
set rAmount(rAmount) { set rAmount(rAmount) {
this._rAmount = Math.round(rAmount * QORT_DECIMALS) this._rAmount = Math.round(rAmount * QORT_DECIMALS);
this._rAmountBytes = this.constructor.utils.int64ToBytes(this._rAmount) this._rAmountBytes = this.constructor.utils.int64ToBytes(this._rAmount);
} }
set rName(rName) { set rName(rName) {
this._rName = rName this._rName = rName;
this._rNameBytes = this.constructor.utils.stringtoUTF8Array(this._rName.toLocaleLowerCase()) this._rNameBytes = this.constructor.utils.stringtoUTF8Array(
this._rNameLength = this.constructor.utils.int32ToBytes(this._rNameBytes.length) this._rName.toLocaleLowerCase()
);
this._rNameLength = this.constructor.utils.int32ToBytes(
this._rNameBytes.length
);
} }
set rDescription(rDescription) { set rDescription(rDescription) {
this._rDescription = rDescription this._rDescription = rDescription;
this._rDescriptionBytes = this.constructor.utils.stringtoUTF8Array(this._rDescription.toLocaleLowerCase()) this._rDescriptionBytes = this.constructor.utils.stringtoUTF8Array(
this._rDescriptionLength = this.constructor.utils.int32ToBytes(this._rDescriptionBytes.length) this._rDescription.toLocaleLowerCase()
);
this._rDescriptionLength = this.constructor.utils.int32ToBytes(
this._rDescriptionBytes.length
);
} }
set atType(atType) { set atType(atType) {
this._atType = atType this._atType = atType;
this._atTypeBytes = this.constructor.utils.stringtoUTF8Array(this._atType) this._atTypeBytes = this.constructor.utils.stringtoUTF8Array(this._atType);
this._atTypeLength = this.constructor.utils.int32ToBytes(this._atTypeBytes.length) this._atTypeLength = this.constructor.utils.int32ToBytes(
this._atTypeBytes.length
);
} }
set rTags(rTags) { set rTags(rTags) {
this._rTags = rTags this._rTags = rTags;
this._rTagsBytes = this.constructor.utils.stringtoUTF8Array(this._rTags.toLocaleLowerCase()) this._rTagsBytes = this.constructor.utils.stringtoUTF8Array(
this._rTagsLength = this.constructor.utils.int32ToBytes(this._rTagsBytes.length) this._rTags.toLocaleLowerCase()
);
this._rTagsLength = this.constructor.utils.int32ToBytes(
this._rTagsBytes.length
);
} }
set rCreationBytes(rCreationBytes) { set rCreationBytes(rCreationBytes) {
const decode = this.constructor.Base58.decode(rCreationBytes) const decode = this.constructor.Base58.decode(rCreationBytes);
this._rCreationBytes = this.constructor.utils.stringtoUTF8Array(decode) this._rCreationBytes = this.constructor.utils.stringtoUTF8Array(decode);
this._rCreationBytesLength = this.constructor.utils.int32ToBytes(this._rCreationBytes.length) this._rCreationBytesLength = this.constructor.utils.int32ToBytes(
this._rCreationBytes.length
);
} }
set rAssetId(rAssetId) { set rAssetId(rAssetId) {
this._rAssetId = this.constructor.utils.int64ToBytes(rAssetId) this._rAssetId = this.constructor.utils.int64ToBytes(rAssetId);
} }
get params() { get params() {
const params = super.params const params = super.params;
params.push( params.push(
this._rNameLength, this._rNameLength,
this._rNameBytes, this._rNameBytes,
@ -72,7 +84,7 @@ export default class DeployAtTransaction extends TransactionBase {
this._rAmountBytes, this._rAmountBytes,
this._rAssetId, this._rAssetId,
this._feeBytes this._feeBytes
) );
return params return params;
} }
} }

View File

@ -1,42 +1,48 @@
// @ts-nocheck // @ts-nocheck
import { QORT_DECIMALS } from "../constants/constants" import { QORT_DECIMALS } from '../constants/constants';
import TransactionBase from "./TransactionBase" import TransactionBase from './TransactionBase';
export default class GroupBanTransaction extends TransactionBase { export default class GroupBanTransaction extends TransactionBase {
constructor() { constructor() {
super() super();
this.type = 26 this.type = 26;
} }
set rGroupId(rGroupId) { set rGroupId(rGroupId) {
this._rGroupId = rGroupId this._rGroupId = rGroupId;
this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._rGroupId) this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._rGroupId);
} }
set rBanReason(rBanReason) { set rBanReason(rBanReason) {
this._rBanReason = rBanReason this._rBanReason = rBanReason;
this._rBanReasonBytes = this.constructor.utils.stringtoUTF8Array(this._rBanReason) this._rBanReasonBytes = this.constructor.utils.stringtoUTF8Array(
this._rBanReasonLength = this.constructor.utils.int32ToBytes(this._rBanReasonBytes.length) this._rBanReason
);
this._rBanReasonLength = this.constructor.utils.int32ToBytes(
this._rBanReasonBytes.length
);
} }
set rBanTime(rBanTime) { set rBanTime(rBanTime) {
this._rBanTime = rBanTime this._rBanTime = rBanTime;
this._rBanTimeBytes = this.constructor.utils.int32ToBytes(this._rBanTime) this._rBanTimeBytes = this.constructor.utils.int32ToBytes(this._rBanTime);
} }
set recipient(recipient) { set recipient(recipient) {
this._recipient = recipient instanceof Uint8Array ? recipient : this.constructor.Base58.decode(recipient) this._recipient =
this.theRecipient = recipient recipient instanceof Uint8Array
? recipient
: this.constructor.Base58.decode(recipient);
this.theRecipient = recipient;
} }
set fee(fee) { set fee(fee) {
this._fee = fee * QORT_DECIMALS this._fee = fee * QORT_DECIMALS;
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee) this._feeBytes = this.constructor.utils.int64ToBytes(this._fee);
} }
get params() { get params() {
const params = super.params const params = super.params;
params.push( params.push(
this._rGroupIdBytes, this._rGroupIdBytes,
this._recipient, this._recipient,
@ -44,7 +50,7 @@ export default class GroupBanTransaction extends TransactionBase {
this._rBanReasonBytes, this._rBanReasonBytes,
this._rBanTimeBytes, this._rBanTimeBytes,
this._feeBytes this._feeBytes
) );
return params return params;
} }
} }

View File

@ -1,53 +1,57 @@
// @ts-nocheck // @ts-nocheck
import ChatBase from './ChatBase';
import ChatBase from './ChatBase' import { CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP } from '../constants/constants';
import { CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP } from '../constants/constants'
export default class GroupChatTransaction extends ChatBase { export default class GroupChatTransaction extends ChatBase {
constructor() { constructor() {
super(); super();
this.type = 18 this.type = 18;
this.fee = 0 this.fee = 0;
} }
set proofOfWorkNonce(proofOfWorkNonce) { set proofOfWorkNonce(proofOfWorkNonce) {
this._proofOfWorkNonce = this.constructor.utils.int32ToBytes(proofOfWorkNonce) this._proofOfWorkNonce =
this.constructor.utils.int32ToBytes(proofOfWorkNonce);
} }
set hasReceipient(hasReceipient) { set hasReceipient(hasReceipient) {
this._hasReceipient = new Uint8Array(1) this._hasReceipient = new Uint8Array(1);
this._hasReceipient[0] = hasReceipient this._hasReceipient[0] = hasReceipient;
} }
set message(message) { set message(message) {
this.messageText = message this.messageText = message;
this._message = this.constructor.utils.stringtoUTF8Array(message) this._message = this.constructor.utils.stringtoUTF8Array(message);
this._messageLength = this.constructor.utils.int32ToBytes(this._message.length) this._messageLength = this.constructor.utils.int32ToBytes(
this._message.length
);
} }
set hasChatReference(hasChatReference) { set hasChatReference(hasChatReference) {
this._hasChatReference = new Uint8Array(1) this._hasChatReference = new Uint8Array(1);
this._hasChatReference[0] = hasChatReference this._hasChatReference[0] = hasChatReference;
} }
set chatReference(chatReference) { set chatReference(chatReference) {
this._chatReference = chatReference instanceof Uint8Array ? chatReference : this.constructor.Base58.decode(chatReference) this._chatReference =
chatReference instanceof Uint8Array
? chatReference
: this.constructor.Base58.decode(chatReference);
} }
set isEncrypted(isEncrypted) { set isEncrypted(isEncrypted) {
this._isEncrypted = new Uint8Array(1) this._isEncrypted = new Uint8Array(1);
this._isEncrypted[0] = isEncrypted this._isEncrypted[0] = isEncrypted;
} }
set isText(isText) { set isText(isText) {
this._isText = new Uint8Array(1) this._isText = new Uint8Array(1);
this._isText[0] = isText this._isText[0] = isText;
} }
get params() { get params() {
const params = super.params const params = super.params;
params.push( params.push(
this._proofOfWorkNonce, this._proofOfWorkNonce,
this._hasReceipient, this._hasReceipient,
@ -56,17 +60,20 @@ export default class GroupChatTransaction extends ChatBase {
this._isEncrypted, this._isEncrypted,
this._isText, this._isText,
this._feeBytes this._feeBytes
) );
// After the feature trigger timestamp we need to include chat reference // After the feature trigger timestamp we need to include chat reference
if (new Date(this._timestamp).getTime() >= CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP) { if (
params.push(this._hasChatReference) new Date(this._timestamp).getTime() >=
CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP
) {
params.push(this._hasChatReference);
if (this._hasChatReference[0] == 1) { if (this._hasChatReference[0] == 1) {
params.push(this._chatReference) params.push(this._chatReference);
} }
} }
return params return params;
} }
} }

View File

@ -1,42 +1,46 @@
// @ts-nocheck // @ts-nocheck
import { QORT_DECIMALS } from "../constants/constants" import { QORT_DECIMALS } from '../constants/constants';
import TransactionBase from "./TransactionBase" import TransactionBase from './TransactionBase';
export default class GroupInviteTransaction extends TransactionBase { export default class GroupInviteTransaction extends TransactionBase {
constructor() { constructor() {
super() super();
this.type = 29 this.type = 29;
} }
set rGroupId(rGroupId) { set rGroupId(rGroupId) {
this._rGroupId = rGroupId this._rGroupId = rGroupId;
this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._rGroupId) this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._rGroupId);
} }
set rInviteTime(rInviteTime) { set rInviteTime(rInviteTime) {
this._rInviteTime = rInviteTime this._rInviteTime = rInviteTime;
this._rInviteTimeBytes = this.constructor.utils.int32ToBytes(this._rInviteTime) this._rInviteTimeBytes = this.constructor.utils.int32ToBytes(
this._rInviteTime
);
} }
set recipient(recipient) { set recipient(recipient) {
this._recipient = recipient instanceof Uint8Array ? recipient : this.constructor.Base58.decode(recipient) this._recipient =
this.theRecipient = recipient recipient instanceof Uint8Array
? recipient
: this.constructor.Base58.decode(recipient);
this.theRecipient = recipient;
} }
set fee(fee) { set fee(fee) {
this._fee = fee * QORT_DECIMALS this._fee = fee * QORT_DECIMALS;
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee) this._feeBytes = this.constructor.utils.int64ToBytes(this._fee);
} }
get params() { get params() {
const params = super.params const params = super.params;
params.push( params.push(
this._rGroupIdBytes, this._rGroupIdBytes,
this._recipient, this._recipient,
this._rInviteTimeBytes, this._rInviteTimeBytes,
this._feeBytes this._feeBytes
) );
return params return params;
} }
} }

View File

@ -1,46 +1,50 @@
// @ts-nocheck // @ts-nocheck
import { QORT_DECIMALS } from '../constants/constants';
import { QORT_DECIMALS } from "../constants/constants" import TransactionBase from './TransactionBase';
import TransactionBase from "./TransactionBase"
export default class GroupKickTransaction extends TransactionBase { export default class GroupKickTransaction extends TransactionBase {
constructor() { constructor() {
super() super();
this.type = 28 this.type = 28;
} }
set rGroupId(rGroupId) { set rGroupId(rGroupId) {
this._rGroupId = rGroupId this._rGroupId = rGroupId;
this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._rGroupId) this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._rGroupId);
} }
set rBanReason(rBanReason) { set rBanReason(rBanReason) {
this._rBanReason = rBanReason this._rBanReason = rBanReason;
this._rBanReasonBytes = this.constructor.utils.stringtoUTF8Array(this._rBanReason) this._rBanReasonBytes = this.constructor.utils.stringtoUTF8Array(
this._rBanReasonLength = this.constructor.utils.int32ToBytes(this._rBanReasonBytes.length) this._rBanReason
);
this._rBanReasonLength = this.constructor.utils.int32ToBytes(
this._rBanReasonBytes.length
);
} }
set recipient(recipient) { set recipient(recipient) {
this._recipient = recipient instanceof Uint8Array ? recipient : this.constructor.Base58.decode(recipient) this._recipient =
this.theRecipient = recipient recipient instanceof Uint8Array
? recipient
: this.constructor.Base58.decode(recipient);
this.theRecipient = recipient;
} }
set fee(fee) { set fee(fee) {
this._fee = fee * QORT_DECIMALS this._fee = fee * QORT_DECIMALS;
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee) this._feeBytes = this.constructor.utils.int64ToBytes(this._fee);
} }
get params() { get params() {
const params = super.params const params = super.params;
params.push( params.push(
this._rGroupIdBytes, this._rGroupIdBytes,
this._recipient, this._recipient,
this._rBanReasonLength, this._rBanReasonLength,
this._rBanReasonBytes, this._rBanReasonBytes,
this._feeBytes this._feeBytes
) );
return params return params;
} }
} }

View File

@ -1,38 +1,33 @@
// @ts-nocheck // @ts-nocheck
import { QORT_DECIMALS } from "../constants/constants" import { QORT_DECIMALS } from '../constants/constants';
import TransactionBase from "./TransactionBase" import TransactionBase from './TransactionBase';
export default class JoinGroupTransaction extends TransactionBase { export default class JoinGroupTransaction extends TransactionBase {
constructor() { constructor() {
super() super();
this.type = 31 this.type = 31;
} }
set fee(fee) { set fee(fee) {
this._fee = fee * QORT_DECIMALS this._fee = fee * QORT_DECIMALS;
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee) this._feeBytes = this.constructor.utils.int64ToBytes(this._fee);
} }
set registrantAddress(registrantAddress) { set registrantAddress(registrantAddress) {
this._registrantAddress = registrantAddress instanceof Uint8Array ? registrantAddress : this.constructor.Base58.decode(registrantAddress) this._registrantAddress =
registrantAddress instanceof Uint8Array
? registrantAddress
: this.constructor.Base58.decode(registrantAddress);
} }
set rGroupId(rGroupId) { set rGroupId(rGroupId) {
this._rGroupId = rGroupId this._rGroupId = rGroupId;
this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._rGroupId) this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._rGroupId);
} }
get params() { get params() {
const params = super.params const params = super.params;
params.push( params.push(this._rGroupIdBytes, this._feeBytes);
this._rGroupIdBytes, return params;
this._feeBytes
)
return params
} }
} }

View File

@ -1,35 +1,34 @@
// @ts-nocheck // @ts-nocheck
import { QORT_DECIMALS } from "../constants/constants" import { QORT_DECIMALS } from '../constants/constants';
import TransactionBase from "./TransactionBase" import TransactionBase from './TransactionBase';
export default class LeaveGroupTransaction extends TransactionBase { export default class LeaveGroupTransaction extends TransactionBase {
constructor() { constructor() {
super() super();
this.type = 32 this.type = 32;
} }
set fee(fee) { set fee(fee) {
this._fee = fee * QORT_DECIMALS this._fee = fee * QORT_DECIMALS;
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee) this._feeBytes = this.constructor.utils.int64ToBytes(this._fee);
} }
set registrantAddress(registrantAddress) { set registrantAddress(registrantAddress) {
this._registrantAddress = registrantAddress instanceof Uint8Array ? registrantAddress : this.constructor.Base58.decode(registrantAddress) this._registrantAddress =
registrantAddress instanceof Uint8Array
? registrantAddress
: this.constructor.Base58.decode(registrantAddress);
} }
set rGroupId(rGroupId) { set rGroupId(rGroupId) {
this._rGroupId = rGroupId this._rGroupId = rGroupId;
this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._rGroupId) this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._rGroupId);
} }
get params() { get params() {
const params = super.params const params = super.params;
params.push( params.push(this._rGroupIdBytes, this._feeBytes);
this._rGroupIdBytes, return params;
this._feeBytes
)
return params
} }
} }

View File

@ -1,38 +1,36 @@
// @ts-nocheck // @ts-nocheck
import { QORT_DECIMALS } from '../constants/constants' import { QORT_DECIMALS } from '../constants/constants';
import TransactionBase from './TransactionBase' import TransactionBase from './TransactionBase';
export default class PaymentTransaction extends TransactionBase { export default class PaymentTransaction extends TransactionBase {
constructor() { constructor() {
super() super();
this.type = 2 this.type = 2;
} }
set recipient(recipient) { set recipient(recipient) {
this._recipient = recipient instanceof Uint8Array ? recipient : this.constructor.Base58.decode(recipient) this._recipient =
recipient instanceof Uint8Array
? recipient
: this.constructor.Base58.decode(recipient);
} }
set dialogto(dialogto) { set dialogto(dialogto) {
this._dialogto = dialogto this._dialogto = dialogto;
} }
set dialogamount(dialogamount) { set dialogamount(dialogamount) {
this._dialogamount = dialogamount this._dialogamount = dialogamount;
} }
set amount(amount) { set amount(amount) {
this._amount = Math.round(amount * QORT_DECIMALS) this._amount = Math.round(amount * QORT_DECIMALS);
this._amountBytes = this.constructor.utils.int64ToBytes(this._amount) this._amountBytes = this.constructor.utils.int64ToBytes(this._amount);
} }
get params() { get params() {
const params = super.params const params = super.params;
params.push( params.push(this._recipient, this._amountBytes, this._feeBytes);
this._recipient, return params;
this._amountBytes,
this._feeBytes
)
return params
} }
} }

View File

@ -1,42 +1,44 @@
// @ts-nocheck // @ts-nocheck
import { QORT_DECIMALS } from "../constants/constants" import { QORT_DECIMALS } from '../constants/constants';
import TransactionBase from "./TransactionBase" import TransactionBase from './TransactionBase';
export default class RegisterNameTransaction extends TransactionBase { export default class RegisterNameTransaction extends TransactionBase {
constructor() { constructor() {
super() super();
this.type = 3 this.type = 3;
} }
set fee(fee) { set fee(fee) {
this._fee = fee * QORT_DECIMALS this._fee = fee * QORT_DECIMALS;
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee) this._feeBytes = this.constructor.utils.int64ToBytes(this._fee);
} }
set name(name) { set name(name) {
this.nameText = name this.nameText = name;
this._nameBytes = this.constructor.utils.stringtoUTF8Array(name) this._nameBytes = this.constructor.utils.stringtoUTF8Array(name);
this._nameLength = this.constructor.utils.int32ToBytes(this._nameBytes.length) this._nameLength = this.constructor.utils.int32ToBytes(
this._nameBytes.length
);
} }
set value(value) { set value(value) {
this.valueText = value.length === 0 ? "Registered Name on the Qortal Chain" : value this.valueText =
this._valueBytes = this.constructor.utils.stringtoUTF8Array(this.valueText) value.length === 0 ? 'Registered Name on the Qortal Chain' : value;
this._valueLength = this.constructor.utils.int32ToBytes(this._valueBytes.length) this._valueBytes = this.constructor.utils.stringtoUTF8Array(this.valueText);
this._valueLength = this.constructor.utils.int32ToBytes(
this._valueBytes.length
);
} }
get params() { get params() {
const params = super.params const params = super.params;
params.push( params.push(
this._nameLength, this._nameLength,
this._nameBytes, this._nameBytes,
this._valueLength, this._valueLength,
this._valueBytes, this._valueBytes,
this._feeBytes this._feeBytes
) );
return params return params;
} }
} }

View File

@ -1,38 +1,34 @@
// @ts-nocheck // @ts-nocheck
import { QORT_DECIMALS } from "../constants/constants" import { QORT_DECIMALS } from '../constants/constants';
import TransactionBase from "./TransactionBase" import TransactionBase from './TransactionBase';
export default class RemoveGroupAdminTransaction extends TransactionBase { export default class RemoveGroupAdminTransaction extends TransactionBase {
constructor() { constructor() {
super() super();
this.type = 25 this.type = 25;
} }
set rGroupId(rGroupId) { set rGroupId(rGroupId) {
this._rGroupId = rGroupId this._rGroupId = rGroupId;
this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._rGroupId) this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._rGroupId);
} }
set recipient(recipient) { set recipient(recipient) {
this._recipient = recipient instanceof Uint8Array ? recipient : this.constructor.Base58.decode(recipient) this._recipient =
this.theRecipient = recipient recipient instanceof Uint8Array
? recipient
: this.constructor.Base58.decode(recipient);
this.theRecipient = recipient;
} }
set fee(fee) { set fee(fee) {
this._fee = fee * QORT_DECIMALS this._fee = fee * QORT_DECIMALS;
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee) this._feeBytes = this.constructor.utils.int64ToBytes(this._fee);
} }
get params() { get params() {
const params = super.params const params = super.params;
params.push( params.push(this._rGroupIdBytes, this._recipient, this._feeBytes);
this._rGroupIdBytes, return params;
this._recipient,
this._feeBytes
)
return params
} }
} }

View File

@ -1,46 +1,50 @@
// @ts-nocheck // @ts-nocheck
import { DYNAMIC_FEE_TIMESTAMP } from "../constants/constants" import { DYNAMIC_FEE_TIMESTAMP } from '../constants/constants';
import Base58 from "../deps/Base58" import Base58 from '../deps/Base58';
import publicKeyToAddress from "../utils/generateWallet/publicKeyToAddress" import publicKeyToAddress from '../utils/generateWallet/publicKeyToAddress';
import TransactionBase from "./TransactionBase" import TransactionBase from './TransactionBase';
export default class RemoveRewardShareTransaction extends TransactionBase { export default class RemoveRewardShareTransaction extends TransactionBase {
constructor() { constructor() {
super() super();
this.type = 38 this.type = 38;
} }
set rewardShareKeyPairPublicKey(rewardShareKeyPairPublicKey) { set rewardShareKeyPairPublicKey(rewardShareKeyPairPublicKey) {
this._rewardShareKeyPairPublicKey = Base58.decode(rewardShareKeyPairPublicKey) this._rewardShareKeyPairPublicKey = Base58.decode(
rewardShareKeyPairPublicKey
);
} }
set recipient(recipient) { set recipient(recipient) {
const _address = publicKeyToAddress(this._keyPair.publicKey) const _address = publicKeyToAddress(this._keyPair.publicKey);
this._recipient = recipient instanceof Uint8Array ? recipient : this.constructor.Base58.decode(recipient) this._recipient =
recipient instanceof Uint8Array
? recipient
: this.constructor.Base58.decode(recipient);
if (new Date(this._timestamp).getTime() >= DYNAMIC_FEE_TIMESTAMP) { if (new Date(this._timestamp).getTime() >= DYNAMIC_FEE_TIMESTAMP) {
this.fee = _address === recipient ? 0 : 0.01 this.fee = _address === recipient ? 0 : 0.01;
} else { } else {
this.fee = _address === recipient ? 0 : 0.001 this.fee = _address === recipient ? 0 : 0.001;
} }
} }
set percentageShare(share) { set percentageShare(share) {
this._percentageShare = share * 100 this._percentageShare = share * 100;
this._percentageShareBytes = this.constructor.utils.int64ToBytes(this._percentageShare) this._percentageShareBytes = this.constructor.utils.int64ToBytes(
this._percentageShare
);
} }
get params() { get params() {
const params = super.params const params = super.params;
params.push( params.push(
this._recipient, this._recipient,
this._rewardShareKeyPairPublicKey, this._rewardShareKeyPairPublicKey,
this._percentageShareBytes, this._percentageShareBytes,
this._feeBytes this._feeBytes
) );
return params return params;
} }
} }

View File

@ -1,60 +1,86 @@
// @ts-nocheck // @ts-nocheck
import TransactionBase from './TransactionBase' import TransactionBase from './TransactionBase';
import { Sha256 } from 'asmcrypto.js';
import { Sha256 } from 'asmcrypto.js' import nacl from '../deps/nacl-fast';
import nacl from '../deps/nacl-fast' import ed2curve from '../deps/ed2curve';
import ed2curve from '../deps/ed2curve' import { DYNAMIC_FEE_TIMESTAMP } from '../constants/constants';
import { DYNAMIC_FEE_TIMESTAMP } from '../constants/constants' import publicKeyToAddress from '../utils/generateWallet/publicKeyToAddress';
import publicKeyToAddress from '../utils/generateWallet/publicKeyToAddress'
export default class RewardShareTransaction extends TransactionBase { export default class RewardShareTransaction extends TransactionBase {
constructor() { constructor() {
super() super();
this.type = 38 this.type = 38;
} }
set recipientPublicKey(recipientPublicKey) { set recipientPublicKey(recipientPublicKey) {
this._base58RecipientPublicKey = recipientPublicKey instanceof Uint8Array ? this.constructor.Base58.encode(recipientPublicKey) : recipientPublicKey this._base58RecipientPublicKey =
this._recipientPublicKey = this.constructor.Base58.decode(this._base58RecipientPublicKey) recipientPublicKey instanceof Uint8Array
this.recipient = publicKeyToAddress(this._recipientPublicKey) ? this.constructor.Base58.encode(recipientPublicKey)
: recipientPublicKey;
this._recipientPublicKey = this.constructor.Base58.decode(
this._base58RecipientPublicKey
);
this.recipient = publicKeyToAddress(this._recipientPublicKey);
const convertedPrivateKey = ed2curve.convertSecretKey(this._keyPair.privateKey) const convertedPrivateKey = ed2curve.convertSecretKey(
const convertedPublicKey = ed2curve.convertPublicKey(this._recipientPublicKey) this._keyPair.privateKey
const sharedSecret = new Uint8Array(32) );
const convertedPublicKey = ed2curve.convertPublicKey(
this._recipientPublicKey
);
const sharedSecret = new Uint8Array(32);
nacl.lowlevel.crypto_scalarmult(sharedSecret, convertedPrivateKey, convertedPublicKey) nacl.lowlevel.crypto_scalarmult(
sharedSecret,
convertedPrivateKey,
convertedPublicKey
);
this._rewardShareSeed = new Sha256().process(sharedSecret).finish().result this._rewardShareSeed = new Sha256().process(sharedSecret).finish().result;
this._base58RewardShareSeed = this.constructor.Base58.encode(this._rewardShareSeed) this._base58RewardShareSeed = this.constructor.Base58.encode(
this._rewardShareKeyPair = nacl.sign.keyPair.fromSeed(this._rewardShareSeed) this._rewardShareSeed
);
this._rewardShareKeyPair = nacl.sign.keyPair.fromSeed(
this._rewardShareSeed
);
if (new Date(this._timestamp).getTime() >= DYNAMIC_FEE_TIMESTAMP) { if (new Date(this._timestamp).getTime() >= DYNAMIC_FEE_TIMESTAMP) {
this.fee = (recipientPublicKey === this.constructor.Base58.encode(this._keyPair.publicKey) ? 0 : 0.01) this.fee =
recipientPublicKey ===
this.constructor.Base58.encode(this._keyPair.publicKey)
? 0
: 0.01;
} else { } else {
this.fee = (recipientPublicKey === this.constructor.Base58.encode(this._keyPair.publicKey) ? 0 : 0.001) this.fee =
recipientPublicKey ===
this.constructor.Base58.encode(this._keyPair.publicKey)
? 0
: 0.001;
} }
} }
set recipient(recipient) { set recipient(recipient) {
this._recipient = recipient instanceof Uint8Array ? recipient : this.constructor.Base58.decode(recipient) this._recipient =
recipient instanceof Uint8Array
? recipient
: this.constructor.Base58.decode(recipient);
} }
set percentageShare(share) { set percentageShare(share) {
this._percentageShare = share * 100 this._percentageShare = share * 100;
this._percentageShareBytes = this.constructor.utils.int64ToBytes(this._percentageShare) this._percentageShareBytes = this.constructor.utils.int64ToBytes(
this._percentageShare
);
} }
get params() { get params() {
const params = super.params const params = super.params;
params.push( params.push(
this._recipient, this._recipient,
this._rewardShareKeyPair.publicKey, this._rewardShareKeyPair.publicKey,
this._percentageShareBytes, this._percentageShareBytes,
this._feeBytes this._feeBytes
) );
return params return params;
} }
} }

View File

@ -1,40 +1,40 @@
// @ts-nocheck // @ts-nocheck
import { QORT_DECIMALS } from "../constants/constants" import { QORT_DECIMALS } from '../constants/constants';
import TransactionBase from "./TransactionBase" import TransactionBase from './TransactionBase';
export default class SellNameTransacion extends TransactionBase { export default class SellNameTransacion extends TransactionBase {
constructor() { constructor() {
super() super();
this.type = 5 this.type = 5;
} }
set fee(fee) { set fee(fee) {
this._fee = fee * QORT_DECIMALS this._fee = fee * QORT_DECIMALS;
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee) this._feeBytes = this.constructor.utils.int64ToBytes(this._fee);
} }
set name(name) { set name(name) {
this.nameText = name this.nameText = name;
this._nameBytes = this.constructor.utils.stringtoUTF8Array(name) this._nameBytes = this.constructor.utils.stringtoUTF8Array(name);
this._nameLength = this.constructor.utils.int32ToBytes(this._nameBytes.length) this._nameLength = this.constructor.utils.int32ToBytes(
this._nameBytes.length
);
} }
set sellPrice(sellPrice) { set sellPrice(sellPrice) {
this.showSellPrice = sellPrice this.showSellPrice = sellPrice;
this._sellPrice = sellPrice * QORT_DECIMALS this._sellPrice = sellPrice * QORT_DECIMALS;
this._sellPriceBytes = this.constructor.utils.int64ToBytes(this._sellPrice) this._sellPriceBytes = this.constructor.utils.int64ToBytes(this._sellPrice);
} }
get params() { get params() {
const params = super.params const params = super.params;
params.push( params.push(
this._nameLength, this._nameLength,
this._nameBytes, this._nameBytes,
this._sellPriceBytes, this._sellPriceBytes,
this._feeBytes this._feeBytes
) );
return params return params;
} }
} }

View File

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

View File

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

View File

@ -12,31 +12,30 @@ export class TradeBotRespondMultipleRequest {
} }
createTransaction(txnReq) { createTransaction(txnReq) {
this.addresses(txnReq.addresses) this.addresses(txnReq.addresses);
this.foreignKey(txnReq.foreignKey) this.foreignKey(txnReq.foreignKey);
this.receivingAddress(txnReq.receivingAddress) this.receivingAddress(txnReq.receivingAddress);
return this.txnRequest() return this.txnRequest();
} }
addresses(addresses) { addresses(addresses) {
this._addresses = addresses this._addresses = addresses;
} }
foreignKey(foreignKey) { foreignKey(foreignKey) {
this._foreignKey = foreignKey this._foreignKey = foreignKey;
} }
receivingAddress(receivingAddress) { receivingAddress(receivingAddress) {
this._receivingAddress = receivingAddress this._receivingAddress = receivingAddress;
} }
txnRequest() { txnRequest() {
return { return {
addresses: this._addresses, addresses: this._addresses,
foreignKey: this._foreignKey, foreignKey: this._foreignKey,
receivingAddress: this._receivingAddress receivingAddress: this._receivingAddress,
} };
} }
} }

View File

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

View File

@ -1,101 +1,118 @@
// @ts-nocheck // @ts-nocheck
import nacl from '../deps/nacl-fast' import nacl from '../deps/nacl-fast';
import Base58 from '../deps/Base58' import Base58 from '../deps/Base58';
import utils from '../utils/utils' import utils from '../utils/utils';
import { QORT_DECIMALS, TX_TYPES } from '../constants/constants.js' import { QORT_DECIMALS, TX_TYPES } from '../constants/constants.js';
export default class TransactionBase { export default class TransactionBase {
static get utils() { static get utils() {
return utils return utils;
} }
static get nacl() { static get nacl() {
return nacl return nacl;
} }
static get Base58() { static get Base58() {
return Base58 return Base58;
} }
constructor() { constructor() {
this.fee = 0 this.fee = 0;
this.groupID = 0 this.groupID = 0;
this.timestamp = Date.now() this.timestamp = Date.now();
this.tests = [ this.tests = [
() => { () => {
if (!(this._type >= 1 && this._type in TX_TYPES)) { if (!(this._type >= 1 && this._type in TX_TYPES)) {
return 'Invalid type: ' + this.type return 'Invalid type: ' + this.type;
} }
return true return true;
}, },
() => { () => {
if (this._fee < 0) { if (this._fee < 0) {
return 'Invalid fee: ' + this._fee / QORT_DECIMALS return 'Invalid fee: ' + this._fee / QORT_DECIMALS;
} }
return true return true;
}, },
() => { () => {
if (this._groupID < 0 || !Number.isInteger(this._groupID)) { if (this._groupID < 0 || !Number.isInteger(this._groupID)) {
return 'Invalid groupID: ' + this._groupID return 'Invalid groupID: ' + this._groupID;
} }
return true return true;
}, },
() => { () => {
if (!(new Date(this._timestamp)).getTime() > 0) { if (!new Date(this._timestamp).getTime() > 0) {
return 'Invalid timestamp: ' + this._timestamp return 'Invalid timestamp: ' + this._timestamp;
} }
return true return true;
}, },
() => { () => {
if (!(this._lastReference instanceof Uint8Array && this._lastReference.byteLength == 64)) { if (
!(
this._lastReference instanceof Uint8Array &&
this._lastReference.byteLength == 64
)
) {
if (this._lastReference == 0) { if (this._lastReference == 0) {
return 'Invalid last reference. Please ensure that you have at least 0.001 QORT for the transaction fee.' 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 'Invalid last reference: ' + this._lastReference;
} }
return true return true;
}, },
() => { () => {
if (!(this._keyPair)) { if (!this._keyPair) {
return 'keyPair must be specified' return 'keyPair must be specified';
} }
if (!(this._keyPair.publicKey instanceof Uint8Array && this._keyPair.publicKey.byteLength === 32)) { if (
return 'Invalid publicKey' !(
this._keyPair.publicKey instanceof Uint8Array &&
this._keyPair.publicKey.byteLength === 32
)
) {
return 'Invalid publicKey';
} }
if (!(this._keyPair.privateKey instanceof Uint8Array && this._keyPair.privateKey.byteLength === 64)) { if (
return 'Invalid privateKey' !(
this._keyPair.privateKey instanceof Uint8Array &&
this._keyPair.privateKey.byteLength === 64
)
) {
return 'Invalid privateKey';
} }
return true return true;
} },
] ];
} }
set keyPair(keyPair) { set keyPair(keyPair) {
this._keyPair = keyPair this._keyPair = keyPair;
} }
set type(type) { set type(type) {
this.typeText = TX_TYPES[type] this.typeText = TX_TYPES[type];
this._type = type this._type = type;
this._typeBytes = this.constructor.utils.int32ToBytes(this._type) this._typeBytes = this.constructor.utils.int32ToBytes(this._type);
} }
set groupID(groupID) { set groupID(groupID) {
this._groupID = groupID this._groupID = groupID;
this._groupIDBytes = this.constructor.utils.int32ToBytes(this._groupID) this._groupIDBytes = this.constructor.utils.int32ToBytes(this._groupID);
} }
set timestamp(timestamp) { set timestamp(timestamp) {
this._timestamp = timestamp this._timestamp = timestamp;
this._timestampBytes = this.constructor.utils.int64ToBytes(this._timestamp) this._timestampBytes = this.constructor.utils.int64ToBytes(this._timestamp);
} }
set fee(fee) { set fee(fee) {
this._fee = fee * QORT_DECIMALS this._fee = fee * QORT_DECIMALS;
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee) this._feeBytes = this.constructor.utils.int64ToBytes(this._fee);
} }
set lastReference(lastReference) { set lastReference(lastReference) {
this._lastReference = lastReference instanceof Uint8Array ? lastReference : this.constructor.Base58.decode(lastReference) this._lastReference =
lastReference instanceof Uint8Array
? lastReference
: this.constructor.Base58.decode(lastReference);
} }
get params() { get params() {
@ -104,62 +121,68 @@ export default class TransactionBase {
this._timestampBytes, this._timestampBytes,
this._groupIDBytes, this._groupIDBytes,
this._lastReference, this._lastReference,
this._keyPair.publicKey this._keyPair.publicKey,
] ];
} }
get signedBytes() { get signedBytes() {
if (!this._signedBytes) { if (!this._signedBytes) {
this.sign() this.sign();
} }
return this._signedBytes return this._signedBytes;
} }
validParams() { validParams() {
let finalResult = { let finalResult = {
valid: true valid: true,
} };
this.tests.some(test => { this.tests.some((test) => {
const result = test() const result = test();
if (result !== true) { if (result !== true) {
finalResult = { finalResult = {
valid: false, valid: false,
message: result message: result,
};
return true; // exists the loop
} }
return true // exists the loop });
} return finalResult;
})
return finalResult
} }
generateBase() { generateBase() {
const isValid = this.validParams() const isValid = this.validParams();
if (!isValid.valid) { if (!isValid.valid) {
throw new Error(isValid.message) throw new Error(isValid.message);
} }
let result = new Uint8Array() let result = new Uint8Array();
this.params.forEach(item => { this.params.forEach((item) => {
result = this.constructor.utils.appendBuffer(result, item) result = this.constructor.utils.appendBuffer(result, item);
}) });
this._base = result this._base = result;
return result return result;
} }
sign() { sign() {
if (!this._keyPair) { if (!this._keyPair) {
throw new Error('keyPair not defined') throw new Error('keyPair not defined');
} }
if (!this._base) { if (!this._base) {
this.generateBase() this.generateBase();
} }
this._signature = this.constructor.nacl.sign.detached(this._base, this._keyPair.privateKey) this._signature = this.constructor.nacl.sign.detached(
this._base,
this._keyPair.privateKey
);
this._signedBytes = this.constructor.utils.appendBuffer(this._base, this._signature) this._signedBytes = this.constructor.utils.appendBuffer(
this._base,
this._signature
);
return this._signature return this._signature;
} }
} }

View File

@ -1,35 +1,37 @@
// @ts-nocheck // @ts-nocheck
import { QORT_DECIMALS } from '../constants/constants' import { QORT_DECIMALS } from '../constants/constants';
import TransactionBase from './TransactionBase' import TransactionBase from './TransactionBase';
export default class TransferAssetTransaction extends TransactionBase { export default class TransferAssetTransaction extends TransactionBase {
constructor() { constructor() {
super() super();
this.type = 12 this.type = 12;
} }
set recipient(recipient) { set recipient(recipient) {
this._recipient = recipient instanceof Uint8Array ? recipient : this.constructor.Base58.decode(recipient) this._recipient =
recipient instanceof Uint8Array
? recipient
: this.constructor.Base58.decode(recipient);
} }
set amount(amount) { set amount(amount) {
this._amount = Math.round(amount * QORT_DECIMALS) this._amount = Math.round(amount * QORT_DECIMALS);
this._amountBytes = this.constructor.utils.int64ToBytes(this._amount) this._amountBytes = this.constructor.utils.int64ToBytes(this._amount);
} }
set assetId(assetId) { set assetId(assetId) {
this._assetId = this.constructor.utils.int64ToBytes(assetId) this._assetId = this.constructor.utils.int64ToBytes(assetId);
} }
get params() { get params() {
const params = super.params const params = super.params;
params.push( params.push(
this._recipient, this._recipient,
this._assetId, this._assetId,
this._amountBytes, this._amountBytes,
this._feeBytes this._feeBytes
) );
return params return params;
} }
} }

View File

@ -1,51 +1,53 @@
// @ts-nocheck // @ts-nocheck
import { QORT_DECIMALS } from '../constants/constants';
import { QORT_DECIMALS } from "../constants/constants"; import TransactionBase from './TransactionBase';
import TransactionBase from "./TransactionBase";
export default class UpdateGroupTransaction extends TransactionBase { export default class UpdateGroupTransaction extends TransactionBase {
constructor() { constructor() {
super() super();
this.type = 23 this.type = 23;
} }
set fee(fee) { set fee(fee) {
this._fee = fee * QORT_DECIMALS this._fee = fee * QORT_DECIMALS;
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee) this._feeBytes = this.constructor.utils.int64ToBytes(this._fee);
} }
set newOwner(newOwner) { set newOwner(newOwner) {
this._newOwner = newOwner instanceof Uint8Array ? newOwner : this.constructor.Base58.decode(newOwner) this._newOwner =
newOwner instanceof Uint8Array
? newOwner
: this.constructor.Base58.decode(newOwner);
} }
set newIsOpen(newIsOpen) { set newIsOpen(newIsOpen) {
this._rGroupType = new Uint8Array(1);
this._rGroupType = new Uint8Array(1) this._rGroupType[0] = newIsOpen;
this._rGroupType[0] = newIsOpen
} }
set newDescription(newDescription) { set newDescription(newDescription) {
this._rGroupDescBytes = this.constructor.utils.stringtoUTF8Array(newDescription.toLocaleLowerCase()) this._rGroupDescBytes = this.constructor.utils.stringtoUTF8Array(
this._rGroupDescLength = this.constructor.utils.int32ToBytes(this._rGroupDescBytes.length) newDescription.toLocaleLowerCase()
);
this._rGroupDescLength = this.constructor.utils.int32ToBytes(
this._rGroupDescBytes.length
);
} }
set newApprovalThreshold(newApprovalThreshold) { set newApprovalThreshold(newApprovalThreshold) {
this._rGroupApprovalThreshold = new Uint8Array(1) this._rGroupApprovalThreshold = new Uint8Array(1);
this._rGroupApprovalThreshold[0] = newApprovalThreshold; this._rGroupApprovalThreshold[0] = newApprovalThreshold;
} }
set newMinimumBlockDelay(newMinimumBlockDelay) { set newMinimumBlockDelay(newMinimumBlockDelay) {
this._rGroupMinimumBlockDelayBytes = this.constructor.utils.int32ToBytes(newMinimumBlockDelay) this._rGroupMinimumBlockDelayBytes =
this.constructor.utils.int32ToBytes(newMinimumBlockDelay);
} }
set newMaximumBlockDelay(newMaximumBlockDelay) { set newMaximumBlockDelay(newMaximumBlockDelay) {
this._rGroupMaximumBlockDelayBytes =
this._rGroupMaximumBlockDelayBytes = this.constructor.utils.int32ToBytes(newMaximumBlockDelay) this.constructor.utils.int32ToBytes(newMaximumBlockDelay);
} }
set _groupId(_groupId){ set _groupId(_groupId) {
this._groupBytes = this.constructor.utils.int32ToBytes(_groupId) this._groupBytes = this.constructor.utils.int32ToBytes(_groupId);
} }
get params() { get params() {
const params = super.params const params = super.params;
params.push( params.push(
this._groupBytes, this._groupBytes,
this._newOwner, this._newOwner,
@ -56,7 +58,7 @@ export default class UpdateGroupTransaction extends TransactionBase {
this._rGroupMinimumBlockDelayBytes, this._rGroupMinimumBlockDelayBytes,
this._rGroupMaximumBlockDelayBytes, this._rGroupMaximumBlockDelayBytes,
this._feeBytes this._feeBytes
) );
return params return params;
} }
} }

View File

@ -1,42 +1,47 @@
// @ts-nocheck // @ts-nocheck
import { QORT_DECIMALS } from "../constants/constants" import { QORT_DECIMALS } from '../constants/constants';
import TransactionBase from "./TransactionBase" import TransactionBase from './TransactionBase';
export default class UpdateNameTransaction extends TransactionBase { export default class UpdateNameTransaction extends TransactionBase {
constructor() { constructor() {
super() super();
this.type = 4 this.type = 4;
} }
set fee(fee) { set fee(fee) {
this._fee = fee * QORT_DECIMALS this._fee = fee * QORT_DECIMALS;
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee) this._feeBytes = this.constructor.utils.int64ToBytes(this._fee);
} }
set name(name) { set name(name) {
this.nameText = name this.nameText = name;
this._nameBytes = this.constructor.utils.stringtoUTF8Array(name) this._nameBytes = this.constructor.utils.stringtoUTF8Array(name);
this._nameLength = this.constructor.utils.int32ToBytes(this._nameBytes.length) this._nameLength = this.constructor.utils.int32ToBytes(
this._nameBytes.length
);
} }
set newName(newName) { set newName(newName) {
this.newNameText = newName this.newNameText = newName;
this._newNameBytes = this.constructor.utils.stringtoUTF8Array(newName) this._newNameBytes = this.constructor.utils.stringtoUTF8Array(newName);
this._newNameLength = this.constructor.utils.int32ToBytes(this._newNameBytes.length) this._newNameLength = this.constructor.utils.int32ToBytes(
this._newNameBytes.length
);
} }
set newData(newData) { set newData(newData) {
this.newDataText = newData.length === 0 ? "Registered Name on the Qortal Chain" : newData this.newDataText =
this._newDataBytes = this.constructor.utils.stringtoUTF8Array(this.newDataText) newData.length === 0 ? 'Registered Name on the Qortal Chain' : newData;
this._newDataLength = this.constructor.utils.int32ToBytes(this._newDataBytes.length) this._newDataBytes = this.constructor.utils.stringtoUTF8Array(
this.newDataText
);
this._newDataLength = this.constructor.utils.int32ToBytes(
this._newDataBytes.length
);
} }
get params() { get params() {
const params = super.params const params = super.params;
params.push( params.push(
this._nameLength, this._nameLength,
this._nameBytes, this._nameBytes,
@ -45,7 +50,7 @@ export default class UpdateNameTransaction extends TransactionBase {
this._newDataLength, this._newDataLength,
this._newDataBytes, this._newDataBytes,
this._feeBytes this._feeBytes
) );
return params return params;
} }
} }

View File

@ -1,38 +1,42 @@
// @ts-nocheck // @ts-nocheck
import { QORT_DECIMALS } from '../constants/constants' import { QORT_DECIMALS } from '../constants/constants';
import TransactionBase from './TransactionBase' import TransactionBase from './TransactionBase';
export default class VoteOnPollTransaction extends TransactionBase { export default class VoteOnPollTransaction extends TransactionBase {
constructor() { constructor() {
super() super();
this.type = 9 this.type = 9;
} }
set fee(fee) { set fee(fee) {
this._fee = fee * QORT_DECIMALS this._fee = fee * QORT_DECIMALS;
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee) this._feeBytes = this.constructor.utils.int64ToBytes(this._fee);
} }
set rPollName(rPollName) { set rPollName(rPollName) {
this._rPollName = rPollName this._rPollName = rPollName;
this._rPollNameBytes = this.constructor.utils.stringtoUTF8Array(this._rPollName) this._rPollNameBytes = this.constructor.utils.stringtoUTF8Array(
this._rPollNameLength = this.constructor.utils.int32ToBytes(this._rPollNameBytes.length) this._rPollName
);
this._rPollNameLength = this.constructor.utils.int32ToBytes(
this._rPollNameBytes.length
);
} }
set rOptionIndex(rOptionIndex) { set rOptionIndex(rOptionIndex) {
this._rOptionIndex = rOptionIndex this._rOptionIndex = rOptionIndex;
this._rOptionIndexBytes = this.constructor.utils.int32ToBytes(this._rOptionIndex) this._rOptionIndexBytes = this.constructor.utils.int32ToBytes(
this._rOptionIndex
);
} }
get params() { get params() {
const params = super.params const params = super.params;
params.push( params.push(
this._rPollNameLength, this._rPollNameLength,
this._rPollNameBytes, this._rPollNameBytes,
this._rOptionIndexBytes, this._rOptionIndexBytes,
this._feeBytes this._feeBytes
) );
return params return params;
} }
} }

View File

@ -1,39 +1,40 @@
// @ts-nocheck // @ts-nocheck
import nacl from '../deps/nacl-fast' import nacl from '../deps/nacl-fast';
import utils from '../utils/utils' import utils from '../utils/utils';
export const signChat = (chatBytes, nonce, keyPair) => { export const signChat = (chatBytes, nonce, keyPair) => {
if (!chatBytes) { if (!chatBytes) {
throw new Error('Chat Bytes not defined') throw new Error('Chat Bytes not defined');
} }
if (!nonce) { if (!nonce) {
throw new Error('Nonce not defined') throw new Error('Nonce not defined');
} }
if (!keyPair) { if (!keyPair) {
throw new Error('keyPair not defined') throw new Error('keyPair not defined');
} }
const _nonce = utils.int32ToBytes(nonce) const _nonce = utils.int32ToBytes(nonce);
if (chatBytes.length === undefined) { 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) const chatBytesBuffer = new Uint8Array(_chatBytesBuffer);
chatBytesBuffer.set(_nonce, 112) chatBytesBuffer.set(_nonce, 112);
const signature = nacl.sign.detached(chatBytesBuffer, keyPair.privateKey) const signature = nacl.sign.detached(chatBytesBuffer, keyPair.privateKey);
return utils.appendBuffer(chatBytesBuffer, signature) return utils.appendBuffer(chatBytesBuffer, signature);
} else { } else {
const chatBytesBuffer = new Uint8Array(chatBytes) const chatBytesBuffer = new Uint8Array(chatBytes);
chatBytesBuffer.set(_nonce, 112) chatBytesBuffer.set(_nonce, 112);
const signature = nacl.sign.detached(chatBytesBuffer, keyPair.privateKey) const signature = nacl.sign.detached(chatBytesBuffer, keyPair.privateKey);
return utils.appendBuffer(chatBytesBuffer, signature) return utils.appendBuffer(chatBytesBuffer, signature);
} }
} };

View File

@ -1,30 +1,31 @@
// @ts-nocheck // @ts-nocheck
import nacl from '../deps/nacl-fast';
import nacl from '../deps/nacl-fast' import Base58 from '../deps/Base58';
import Base58 from '../deps/Base58' import utils from '../utils/utils';
import utils from '../utils/utils'
const signTradeBotTransaction = async (unsignedTxn, keyPair) => { const signTradeBotTransaction = async (unsignedTxn, keyPair) => {
if (!unsignedTxn) { if (!unsignedTxn) {
throw new Error('Unsigned Transaction Bytes not defined') throw new Error('Unsigned Transaction Bytes not defined');
} }
if (!keyPair) { if (!keyPair) {
throw new Error('keyPair not defined') throw new Error('keyPair not defined');
} }
const txnBuffer = Base58.decode(unsignedTxn) const txnBuffer = Base58.decode(unsignedTxn);
if (keyPair.privateKey.length === undefined) { 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) {
const privateKey = new Uint8Array(_privateKey) return keyPair.privateKey[key];
const signature = nacl.sign.detached(txnBuffer, privateKey) });
return utils.appendBuffer(txnBuffer, signature) const privateKey = new Uint8Array(_privateKey);
const signature = nacl.sign.detached(txnBuffer, privateKey);
return utils.appendBuffer(txnBuffer, signature);
} else { } else {
const signature = nacl.sign.detached(txnBuffer, keyPair.privateKey) const signature = nacl.sign.detached(txnBuffer, keyPair.privateKey);
return utils.appendBuffer(txnBuffer, signature) return utils.appendBuffer(txnBuffer, signature);
} }
} };
export default signTradeBotTransaction export default signTradeBotTransaction;

View File

@ -1,31 +1,30 @@
// @ts-nocheck // @ts-nocheck
import PaymentTransaction from './PaymentTransaction.js' import PaymentTransaction from './PaymentTransaction.js';
import ChatTransaction from './ChatTransaction.js' import ChatTransaction from './ChatTransaction.js';
import GroupChatTransaction from './GroupChatTransaction.js' import GroupChatTransaction from './GroupChatTransaction.js';
import GroupInviteTransaction from './GroupInviteTransaction.js' import GroupInviteTransaction from './GroupInviteTransaction.js';
import CancelGroupInviteTransaction from './CancelGroupInviteTransaction.js' import CancelGroupInviteTransaction from './CancelGroupInviteTransaction.js';
import GroupKickTransaction from './GroupKickTransaction.js' import GroupKickTransaction from './GroupKickTransaction.js';
import GroupBanTransaction from './GroupBanTransaction.js' import GroupBanTransaction from './GroupBanTransaction.js';
import CancelGroupBanTransaction from './CancelGroupBanTransaction.js' import CancelGroupBanTransaction from './CancelGroupBanTransaction.js';
import CreateGroupTransaction from './CreateGroupTransaction.js' import CreateGroupTransaction from './CreateGroupTransaction.js';
import LeaveGroupTransaction from './LeaveGroupTransaction.js' import LeaveGroupTransaction from './LeaveGroupTransaction.js';
import JoinGroupTransaction from './JoinGroupTransaction.js' import JoinGroupTransaction from './JoinGroupTransaction.js';
import AddGroupAdminTransaction from './AddGroupAdminTransaction.js' import AddGroupAdminTransaction from './AddGroupAdminTransaction.js';
import RemoveGroupAdminTransaction from './RemoveGroupAdminTransaction.js' import RemoveGroupAdminTransaction from './RemoveGroupAdminTransaction.js';
import RegisterNameTransaction from './RegisterNameTransaction.js' import RegisterNameTransaction from './RegisterNameTransaction.js';
import VoteOnPollTransaction from './VoteOnPollTransaction.js' import VoteOnPollTransaction from './VoteOnPollTransaction.js';
import CreatePollTransaction from './CreatePollTransaction.js' import CreatePollTransaction from './CreatePollTransaction.js';
import DeployAtTransaction from './DeployAtTransaction.js' import DeployAtTransaction from './DeployAtTransaction.js';
import RewardShareTransaction from './RewardShareTransaction.js' import RewardShareTransaction from './RewardShareTransaction.js';
import RemoveRewardShareTransaction from './RemoveRewardShareTransaction.js' import RemoveRewardShareTransaction from './RemoveRewardShareTransaction.js';
import UpdateNameTransaction from './UpdateNameTransaction.js' import UpdateNameTransaction from './UpdateNameTransaction.js';
import UpdateGroupTransaction from './UpdateGroupTransaction.js' import UpdateGroupTransaction from './UpdateGroupTransaction.js';
import SellNameTransacion from './SellNameTransacion.js' import SellNameTransacion from './SellNameTransacion.js';
import CancelSellNameTransacion from './CancelSellNameTransacion.js' import CancelSellNameTransacion from './CancelSellNameTransacion.js';
import BuyNameTransacion from './BuyNameTransacion.js' import BuyNameTransacion from './BuyNameTransacion.js';
import TransferAssetTransaction from './TransferAssetTransaction.js' import TransferAssetTransaction from './TransferAssetTransaction.js';
export const transactionTypes = { export const transactionTypes = {
2: PaymentTransaction, 2: PaymentTransaction,
@ -52,17 +51,15 @@ export const transactionTypes = {
31: JoinGroupTransaction, 31: JoinGroupTransaction,
32: LeaveGroupTransaction, 32: LeaveGroupTransaction,
38: RewardShareTransaction, 38: RewardShareTransaction,
381: RemoveRewardShareTransaction 381: RemoveRewardShareTransaction,
} };
export const createTransaction = (type, keyPair, params) => { export const createTransaction = (type, keyPair, params) => {
const tx = new transactionTypes[type]() const tx = new transactionTypes[type]();
tx.keyPair = keyPair tx.keyPair = keyPair;
Object.keys(params).forEach(param => { Object.keys(params).forEach((param) => {
tx[param] = params[param];
});
tx[param] = params[param] return tx;
}) };
return tx
}

View File

@ -17,7 +17,6 @@ export function decodeIfEncoded(input) {
export const isValidBase64 = (str: string): boolean => { export const isValidBase64 = (str: string): boolean => {
if (typeof str !== 'string' || str.length % 4 !== 0) return false; if (typeof str !== 'string' || str.length % 4 !== 0) return false;
const base64Regex = /^[A-Za-z0-9+/]*={0,2}$/; const base64Regex = /^[A-Za-z0-9+/]*={0,2}$/;
return base64Regex.test(str); return base64Regex.test(str);
}; };

View File

@ -5,19 +5,23 @@ import { doInitWorkers, kdf } from '../../deps/kdf';
import PhraseWallet from './phrase-wallet'; import PhraseWallet from './phrase-wallet';
import * as WORDLISTS from './wordlists'; import * as WORDLISTS from './wordlists';
import FileSaver from 'file-saver'; import FileSaver from 'file-saver';
import { Filesystem, Directory, Encoding } from '@capacitor/filesystem'; import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
import { mimeToExtensionMap } from '../memeTypes'; import { mimeToExtensionMap } from '../memeTypes';
export function generateRandomSentence(template = 'adverb verb noun adjective noun adverb verb noun adjective noun adjective verbed adjective noun', maxWordLength = 0, capitalize = true) {
export function generateRandomSentence(
template = 'adverb verb noun adjective noun adverb verb noun adjective noun adjective verbed adjective noun',
maxWordLength = 0,
capitalize = true
) {
const partsOfSpeechMap = { const partsOfSpeechMap = {
'noun': 'nouns', noun: 'nouns',
'adverb': 'adverbs', adverb: 'adverbs',
'adv': 'adverbs', adv: 'adverbs',
'verb': 'verbs', verb: 'verbs',
'interjection': 'interjections', interjection: 'interjections',
'adjective': 'adjectives', adjective: 'adjectives',
'adj': 'adjectives', adj: 'adjectives',
'verbed': 'verbed' verbed: 'verbed',
}; };
let _wordlists = WORDLISTS; let _wordlists = WORDLISTS;
@ -33,7 +37,9 @@ export function generateRandomSentence(template = 'adverb verb noun adjective no
const entropy256 = Math.ceil(entropy / 8); const entropy256 = Math.ceil(entropy / 8);
let buffer = new Uint8Array(entropy256); let buffer = new Uint8Array(entropy256);
crypto.getRandomValues(buffer); crypto.getRandomValues(buffer);
randNum = buffer.reduce((num, value) => num * 256 + value, 0) / Math.pow(256, entropy256); randNum =
buffer.reduce((num, value) => num * 256 + value, 0) /
Math.pow(256, entropy256);
} else { } else {
console.warn('Secure RNG not found. Using Math.random'); console.warn('Secure RNG not found. Using Math.random');
randNum = Math.random(); randNum = Math.random();
@ -48,7 +54,7 @@ export function generateRandomSentence(template = 'adverb verb noun adjective no
function getWord(partOfSpeech) { function getWord(partOfSpeech) {
let words = _wordlists[partsOfSpeechMap[partOfSpeech]]; let words = _wordlists[partsOfSpeechMap[partOfSpeech]];
if (maxWordLength) { if (maxWordLength) {
words = words.filter(word => word.length <= maxWordLength); words = words.filter((word) => word.length <= maxWordLength);
} }
const requiredEntropy = Math.log(words.length) / Math.log(2); const requiredEntropy = Math.log(words.length) / Math.log(2);
const index = Math.floor(_RNG(requiredEntropy) * words.length); const index = Math.floor(_RNG(requiredEntropy) * words.length);
@ -56,68 +62,66 @@ export function generateRandomSentence(template = 'adverb verb noun adjective no
} }
function parse(template) { function parse(template) {
return template.split(/\s+/).map(token => { return template
.split(/\s+/)
.map((token) => {
const match = token.match(/^(\w+)(.*)$/); const match = token.match(/^(\w+)(.*)$/);
if (!match) return token; // No match, return original token if (!match) return token; // No match, return original token
const [ , partOfSpeech, rest ] = match; const [, partOfSpeech, rest] = match;
if (partsOfSpeechMap[partOfSpeech]) { if (partsOfSpeechMap[partOfSpeech]) {
let word = getWord(partOfSpeech); let word = getWord(partOfSpeech);
if (capitalize && token === token[0].toUpperCase() + token.slice(1).toLowerCase()) { if (
capitalize &&
token === token[0].toUpperCase() + token.slice(1).toLowerCase()
) {
word = _capitalize(word); word = _capitalize(word);
} }
return word + rest; return word + rest;
} }
return token; return token;
}).join(' '); })
.join(' ');
} }
return parse(template); return parse(template);
} }
export const createAccount = async(generatedSeedPhrase)=> { export const createAccount = async (generatedSeedPhrase) => {
if(!generatedSeedPhrase) throw new Error('No generated seed-phrase') if (!generatedSeedPhrase) throw new Error('No generated seed-phrase');
const threads = doInitWorkers(crypto.kdfThreads) const threads = doInitWorkers(crypto.kdfThreads);
const seed = await kdf(generatedSeedPhrase, void 0, threads) const seed = await kdf(generatedSeedPhrase, void 0, threads);
const wallet = new PhraseWallet(seed, walletVersion) const wallet = new PhraseWallet(seed, walletVersion);
return wallet return wallet;
};
} const hasExtension = (filename) => {
return filename.includes('.') && filename.split('.').pop().length > 0;
const hasExtension = (filename) => { };
return filename.includes(".") && filename.split(".").pop().length > 0;
};
export const saveFileToDisk = async (data, qortAddress) => {
export const saveFileToDisk = async (data, qortAddress) => {
const dataString = JSON.stringify(data); const dataString = JSON.stringify(data);
const blob = new Blob([dataString], { type: 'application/json' }); const blob = new Blob([dataString], { type: 'application/json' });
const fileName = "qortal_backup_" + qortAddress + ".json"; const fileName = 'qortal_backup_' + qortAddress + '.json';
await FileSaver.saveAs(blob, fileName); await FileSaver.saveAs(blob, fileName);
};
}
export const saveFileToDiskGeneric = async (blob, filename) => { export const saveFileToDiskGeneric = async (blob, filename) => {
const timestamp = new Date() const timestamp = new Date().toISOString().replace(/:/g, '-'); // Safe timestamp for filenames
.toISOString()
.replace(/:/g, "-"); // Safe timestamp for filenames
const fileExtension = mimeToExtensionMap[blob.type] const fileExtension = mimeToExtensionMap[blob.type];
let fileName = filename || "qortal_file_" + timestamp + "." + fileExtension; let fileName = filename || 'qortal_file_' + timestamp + '.' + fileExtension;
fileName = hasExtension(fileName) ? fileName : fileName + "." + fileExtension; fileName = hasExtension(fileName) ? fileName : fileName + '.' + fileExtension;
await FileSaver.saveAs(blob, fileName); await FileSaver.saveAs(blob, fileName);
};
}
export const saveSeedPhraseToDisk = async (data) => { export const saveSeedPhraseToDisk = async (data) => {
const blob = new Blob([data], { type: 'text/plain;charset=utf-8' });
const fileName = 'qortal_seedphrase.txt';
const blob = new Blob([data], { type: 'text/plain;charset=utf-8' }) await FileSaver.saveAs(blob, fileName);
const fileName = "qortal_seedphrase.txt" };
await FileSaver.saveAs(blob, fileName);
}

View File

@ -1,24 +1,30 @@
// @ts-nocheck // @ts-nocheck
import {AES_CBC, HmacSha512} from 'asmcrypto.js' import { AES_CBC, HmacSha512 } from 'asmcrypto.js';
import Base58 from '../../deps/Base58';
import { doInitWorkers, kdf } from '../../deps/kdf.js';
import { crypto as cryptoVals } from '../../constants/decryptWallet.js';
import Base58 from '../../deps/Base58' const getRandomValues = crypto
import { doInitWorkers, kdf } from '../../deps/kdf.js' ? crypto.getRandomValues.bind(crypto)
import { crypto as cryptoVals } from '../../constants/decryptWallet.js' : msCrypto.getRandomValues.bind(msCrypto);
const getRandomValues = crypto ? crypto.getRandomValues.bind(crypto) : msCrypto.getRandomValues.bind(msCrypto)
export const generateSaveWalletData = async (wallet, password, kdfThreads) => { export const generateSaveWalletData = async (wallet, password, kdfThreads) => {
const threads = doInitWorkers(cryptoVals.kdfThreads) const threads = doInitWorkers(cryptoVals.kdfThreads);
let iv = new Uint8Array(16) let iv = new Uint8Array(16);
getRandomValues(iv) getRandomValues(iv);
let salt = new Uint8Array(32) let salt = new Uint8Array(32);
getRandomValues(salt) getRandomValues(salt);
const key = await kdf(password, salt, threads) const key = await kdf(password, salt, threads);
const encryptionKey = key.slice(0, 32) const encryptionKey = key.slice(0, 32);
const macKey = key.slice(32, 63) const macKey = key.slice(32, 63);
const encryptedSeed = AES_CBC.encrypt(wallet._byteSeed, encryptionKey, false, iv) const encryptedSeed = AES_CBC.encrypt(
const mac = new HmacSha512(macKey).process(encryptedSeed).finish().result wallet._byteSeed,
encryptionKey,
false,
iv
);
const mac = new HmacSha512(macKey).process(encryptedSeed).finish().result;
return { return {
address0: wallet._addresses[0].address, address0: wallet._addresses[0].address,
encryptedSeed: Base58.encode(encryptedSeed), encryptedSeed: Base58.encode(encryptedSeed),
@ -26,6 +32,6 @@ export const generateSaveWalletData = async (wallet, password, kdfThreads) => {
iv: Base58.encode(iv), iv: Base58.encode(iv),
version: wallet._walletVersion, version: wallet._walletVersion,
mac: Base58.encode(mac), mac: Base58.encode(mac),
kdfThreads kdfThreads,
} };
} };

View File

@ -2,36 +2,36 @@
// @ts-nocheck // @ts-nocheck
export const EXCEPTIONS = { export const EXCEPTIONS = {
'are': 'were', are: 'were',
'eat': 'ate', eat: 'ate',
'go': 'went', go: 'went',
'have': 'had', have: 'had',
'inherit': 'inherited', inherit: 'inherited',
'is': 'was', is: 'was',
'run': 'ran', run: 'ran',
'sit': 'sat', sit: 'sat',
'visit': 'visited' visit: 'visited',
} };
export const getPastTense = (verb, exceptions = EXCEPTIONS) => { export const getPastTense = (verb, exceptions = EXCEPTIONS) => {
if (exceptions[verb]) { if (exceptions[verb]) {
return exceptions[verb] return exceptions[verb];
} }
if ((/e$/i).test(verb)) { if (/e$/i.test(verb)) {
return verb + 'd' return verb + 'd';
} }
if ((/[aeiou]c$/i).test(verb)) { if (/[aeiou]c$/i.test(verb)) {
return verb + 'ked' return verb + 'ked';
} }
// for american english only // for american english only
if ((/el$/i).test(verb)) { if (/el$/i.test(verb)) {
return verb + 'ed' return verb + 'ed';
} }
if ((/[aeio][aeiou][dlmnprst]$/).test(verb)) { if (/[aeio][aeiou][dlmnprst]$/.test(verb)) {
return verb + 'ed' return verb + 'ed';
} }
if ((/[aeiou][bdglmnprst]$/i).test(verb)) { if (/[aeiou][bdglmnprst]$/i.test(verb)) {
return verb.replace(/(.+[aeiou])([bdglmnprst])/, '$1$2$2ed') return verb.replace(/(.+[aeiou])([bdglmnprst])/, '$1$2$2ed');
} }
return verb + 'ed' return verb + 'ed';
} };

View File

@ -1,7 +1,7 @@
// Author: irontiga <irontiga@gmail.com> // Author: irontiga <irontiga@gmail.com>
import { html, LitElement, css } from 'lit' import { html, LitElement, css } from 'lit';
import * as WORDLISTS from './wordList' import * as WORDLISTS from './wordList';
class RandomSentenceGenerator extends LitElement { class RandomSentenceGenerator extends LitElement {
static get properties() { static get properties() {
@ -11,30 +11,34 @@ class RandomSentenceGenerator extends LitElement {
fetchedWordlistCount: { type: Number, value: 0 }, fetchedWordlistCount: { type: Number, value: 0 },
capitalize: { type: Boolean }, capitalize: { type: Boolean },
partsOfSpeechMap: { type: Object }, partsOfSpeechMap: { type: Object },
templateEntropy: { type: Number, reflect: true, attribute: 'template-entropy' }, templateEntropy: {
maxWordLength: { type: Number, attribute: 'max-word-length' } type: Number,
} reflect: true,
attribute: 'template-entropy',
},
maxWordLength: { type: Number, attribute: 'max-word-length' },
};
} }
constructor() { constructor() {
super() super();
this.template = 'adjective noun verb adverb.' this.template = 'adjective noun verb adverb.';
this.maxWordLength = 0 this.maxWordLength = 0;
this.parsedString = '' this.parsedString = '';
this.fetchedWordlistCount = 0 this.fetchedWordlistCount = 0;
this.capitalize = true this.capitalize = true;
this.partsOfSpeechMap = { this.partsOfSpeechMap = {
'noun': 'nouns', noun: 'nouns',
'adverb': 'adverbs', adverb: 'adverbs',
'adv': 'adverbs', adv: 'adverbs',
'verb': 'verbs', verb: 'verbs',
'interjection': 'interjections', interjection: 'interjections',
'adjective': 'adjectives', adjective: 'adjectives',
'adj': 'adjectives', adj: 'adjectives',
'verbed': 'verbed' verbed: 'verbed',
} };
this.partsOfSpeech = Object.keys(this.partsOfSpeechMap) this.partsOfSpeech = Object.keys(this.partsOfSpeechMap);
this._wordlists = WORDLISTS this._wordlists = WORDLISTS;
} }
static styles = css` static styles = css`
@ -48,126 +52,131 @@ class RandomSentenceGenerator extends LitElement {
`; `;
render() { render() {
return html` return html` <div>${this.parsedString}</div> `;
<div>${this.parsedString}</div>
`
} }
firstUpdated() { firstUpdated() {
// ... // ...
} }
updated(changedProperties) { updated(changedProperties) {
let regen = false let regen = false;
if (changedProperties.has('template')) { if (changedProperties.has('template')) {
regen = true regen = true;
} }
if (changedProperties.has('maxWordLength')) { if (changedProperties.has('maxWordLength')) {
console.dir(this.maxWordLength) console.dir(this.maxWordLength);
if (this.maxWordLength) { if (this.maxWordLength) {
const wl = { ...this._wordlists } const wl = { ...this._wordlists };
for (const partOfSpeech in this._wordlists) { for (const partOfSpeech in this._wordlists) {
if (Array.isArray(this._wordlists[partOfSpeech])) { if (Array.isArray(this._wordlists[partOfSpeech])) {
wl[partOfSpeech] = this._wordlists[partOfSpeech].filter(word => word.length <= this.maxWordLength) wl[partOfSpeech] = this._wordlists[partOfSpeech].filter(
(word) => word.length <= this.maxWordLength
);
} }
} }
this._wordlists = wl this._wordlists = wl;
} }
regen = true regen = true;
} }
if (regen) this.generate() if (regen) this.generate();
} }
_RNG(entropy) { _RNG(entropy) {
if (entropy > 1074) { if (entropy > 1074) {
throw new Error('Javascript can not handle that much entropy!') throw new Error('Javascript can not handle that much entropy!');
} }
let randNum = 0 let randNum = 0;
const crypto = window.crypto || window.msCrypto const crypto = window.crypto || window.msCrypto;
if (crypto) { if (crypto) {
const entropy256 = Math.ceil(entropy / 8) const entropy256 = Math.ceil(entropy / 8);
let buffer = new Uint8Array(entropy256) let buffer = new Uint8Array(entropy256);
crypto.getRandomValues(buffer) crypto.getRandomValues(buffer);
randNum = buffer.reduce((num, value) => { randNum =
return num * value buffer.reduce((num, value) => {
}, 1) / Math.pow(256, entropy256) return num * value;
}, 1) / Math.pow(256, entropy256);
} else { } else {
console.warn('Secure RNG not found. Using Math.random') console.warn('Secure RNG not found. Using Math.random');
randNum = Math.random() randNum = Math.random();
} }
return randNum return randNum;
} }
setRNG(fn) { setRNG(fn) {
this._RNG = fn this._RNG = fn;
} }
_captitalize(str) { _captitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1) return str.charAt(0).toUpperCase() + str.slice(1);
} }
getWord(partOfSpeech) { getWord(partOfSpeech) {
const words = this._wordlists[this.partsOfSpeechMap[partOfSpeech]] const words = this._wordlists[this.partsOfSpeechMap[partOfSpeech]];
const requiredEntropy = Math.log(words.length) / Math.log(2) const requiredEntropy = Math.log(words.length) / Math.log(2);
const index = this._RNG(requiredEntropy) * words.length const index = this._RNG(requiredEntropy) * words.length;
return { return {
word: words[Math.round(index)], word: words[Math.round(index)],
entropy: words.length entropy: words.length,
} };
} }
generate() { generate() {
this.parsedString = this.parse(this.template) this.parsedString = this.parse(this.template);
} }
parse(template) { parse(template) {
const split = template.split(/[\s]/g) const split = template.split(/[\s]/g);
let entropy = 1 let entropy = 1;
const final = split.map(word => { const final = split.map((word) => {
const lower = word.toLowerCase() const lower = word.toLowerCase();
this.partsOfSpeech.some(partOfSpeech => { this.partsOfSpeech.some((partOfSpeech) => {
const partOfSpeechIndex = lower.indexOf(partOfSpeech) // Check it exists const partOfSpeechIndex = lower.indexOf(partOfSpeech); // Check it exists
const nextChar = word.charAt(partOfSpeech.length) const nextChar = word.charAt(partOfSpeech.length);
if (partOfSpeechIndex === 0 && !(nextChar && (nextChar.match(/[a-zA-Z]/g) != null))) { if (
const replacement = this.getWord(partOfSpeech) partOfSpeechIndex === 0 &&
word = replacement.word + word.slice(partOfSpeech.length) // Append the rest of the "word" (punctuation) !(nextChar && nextChar.match(/[a-zA-Z]/g) != null)
entropy = entropy * replacement.entropy ) {
const replacement = this.getWord(partOfSpeech);
word = replacement.word + word.slice(partOfSpeech.length); // Append the rest of the "word" (punctuation)
entropy = entropy * replacement.entropy;
return true return true;
} }
}) });
return word return word;
}) });
this.templateEntropy = Math.floor(Math.log(entropy) / Math.log(8)) this.templateEntropy = Math.floor(Math.log(entropy) / Math.log(8));
return final.join(' ') return final.join(' ');
} }
} }
window.customElements.define('random-sentence-generator', RandomSentenceGenerator) window.customElements.define(
'random-sentence-generator',
RandomSentenceGenerator
);
export default RandomSentenceGenerator export default RandomSentenceGenerator;

View File

@ -1,40 +1,40 @@
export const EXCEPTIONS = { export const EXCEPTIONS = {
'are': 'were', are: 'were',
'eat': 'ate', eat: 'ate',
'go': 'went', go: 'went',
'have': 'had', have: 'had',
'inherit': 'inherited', inherit: 'inherited',
'is': 'was', is: 'was',
'run': 'ran', run: 'ran',
'sit': 'sat', sit: 'sat',
'visit': 'visited' visit: 'visited',
} };
export const getPastTense = (verb, exceptions = EXCEPTIONS) => { export const getPastTense = (verb, exceptions = EXCEPTIONS) => {
if (exceptions[verb]) { if (exceptions[verb]) {
return exceptions[verb] return exceptions[verb];
} }
if ((/e$/i).test(verb)) { if (/e$/i.test(verb)) {
return verb + 'd' return verb + 'd';
} }
if ((/[aeiou]c$/i).test(verb)) { if (/[aeiou]c$/i.test(verb)) {
return verb + 'ked' return verb + 'ked';
} }
// for american english only // for american english only
if ((/el$/i).test(verb)) { if (/el$/i.test(verb)) {
return verb + 'ed' return verb + 'ed';
} }
if ((/[aeio][aeiou][dlmnprst]$/).test(verb)) { if (/[aeio][aeiou][dlmnprst]$/.test(verb)) {
return verb + 'ed' return verb + 'ed';
} }
if ((/[aeiou][bdglmnprst]$/i).test(verb)) { if (/[aeiou][bdglmnprst]$/i.test(verb)) {
return verb.replace(/(.+[aeiou])([bdglmnprst])/, '$1$2$2ed') return verb.replace(/(.+[aeiou])([bdglmnprst])/, '$1$2$2ed');
} }
return verb + 'ed' return verb + 'ed';
} };

View File

@ -4,6 +4,7 @@ import Base58 from '../deps/Base58';
export const validateAddress = (address) => { export const validateAddress = (address) => {
let isAddress = false; let isAddress = false;
try { try {
const decodePubKey = Base58.decode(address); const decodePubKey = Base58.decode(address);