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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,29 +7,29 @@
*/
export default class DeleteTradeOffer {
constructor() {
// ...
}
constructor() {
// ...
}
createTransaction(txnReq) {
this.creatorPublicKey(txnReq.creatorPublicKey)
this.atAddress(txnReq.atAddress)
createTransaction(txnReq) {
this.creatorPublicKey(txnReq.creatorPublicKey);
this.atAddress(txnReq.atAddress);
return this.txnRequest()
}
return this.txnRequest();
}
creatorPublicKey(creatorPublicKey) {
this._creatorPublicKey = creatorPublicKey
}
creatorPublicKey(creatorPublicKey) {
this._creatorPublicKey = creatorPublicKey;
}
atAddress(atAddress) {
this._atAddress = atAddress
}
atAddress(atAddress) {
this._atAddress = atAddress;
}
txnRequest() {
return {
creatorPublicKey: this._creatorPublicKey,
atAddress: this._atAddress
}
}
txnRequest() {
return {
creatorPublicKey: this._creatorPublicKey,
atAddress: this._atAddress,
};
}
}

View File

@ -7,36 +7,35 @@
*/
export class TradeBotRespondMultipleRequest {
constructor() {
// ...
}
constructor() {
// ...
}
createTransaction(txnReq) {
this.addresses(txnReq.addresses)
this.foreignKey(txnReq.foreignKey)
this.receivingAddress(txnReq.receivingAddress)
createTransaction(txnReq) {
this.addresses(txnReq.addresses);
this.foreignKey(txnReq.foreignKey);
this.receivingAddress(txnReq.receivingAddress);
return this.txnRequest()
}
return this.txnRequest();
}
addresses(addresses) {
this._addresses = addresses
}
addresses(addresses) {
this._addresses = addresses;
}
foreignKey(foreignKey) {
this._foreignKey = foreignKey
}
foreignKey(foreignKey) {
this._foreignKey = foreignKey;
}
receivingAddress(receivingAddress) {
this._receivingAddress = receivingAddress
}
receivingAddress(receivingAddress) {
this._receivingAddress = receivingAddress;
}
txnRequest() {
return {
addresses: this._addresses,
foreignKey: this._foreignKey,
receivingAddress: this._receivingAddress
}
}
txnRequest() {
return {
addresses: this._addresses,
foreignKey: this._foreignKey,
receivingAddress: this._receivingAddress,
};
}
}

View File

@ -7,35 +7,35 @@
*/
export default class TradeBotRespondRequest {
constructor() {
// ...
}
constructor() {
// ...
}
createTransaction(txnReq) {
this.atAddress(txnReq.atAddress)
this.foreignKey(txnReq.foreignKey)
this.receivingAddress(txnReq.receivingAddress)
createTransaction(txnReq) {
this.atAddress(txnReq.atAddress);
this.foreignKey(txnReq.foreignKey);
this.receivingAddress(txnReq.receivingAddress);
return this.txnRequest()
}
return this.txnRequest();
}
atAddress(atAddress) {
this._atAddress = atAddress
}
atAddress(atAddress) {
this._atAddress = atAddress;
}
foreignKey(foreignKey) {
this._foreignKey = foreignKey
}
foreignKey(foreignKey) {
this._foreignKey = foreignKey;
}
receivingAddress(receivingAddress) {
this._receivingAddress = receivingAddress
}
receivingAddress(receivingAddress) {
this._receivingAddress = receivingAddress;
}
txnRequest() {
return {
atAddress: this._atAddress,
foreignKey: this._foreignKey,
receivingAddress: this._receivingAddress
}
}
txnRequest() {
return {
atAddress: this._atAddress,
foreignKey: this._foreignKey,
receivingAddress: this._receivingAddress,
};
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,68 +1,65 @@
// @ts-nocheck
import PaymentTransaction from './PaymentTransaction.js'
import ChatTransaction from './ChatTransaction.js'
import GroupChatTransaction from './GroupChatTransaction.js'
import GroupInviteTransaction from './GroupInviteTransaction.js'
import CancelGroupInviteTransaction from './CancelGroupInviteTransaction.js'
import GroupKickTransaction from './GroupKickTransaction.js'
import GroupBanTransaction from './GroupBanTransaction.js'
import CancelGroupBanTransaction from './CancelGroupBanTransaction.js'
import CreateGroupTransaction from './CreateGroupTransaction.js'
import LeaveGroupTransaction from './LeaveGroupTransaction.js'
import JoinGroupTransaction from './JoinGroupTransaction.js'
import AddGroupAdminTransaction from './AddGroupAdminTransaction.js'
import RemoveGroupAdminTransaction from './RemoveGroupAdminTransaction.js'
import RegisterNameTransaction from './RegisterNameTransaction.js'
import VoteOnPollTransaction from './VoteOnPollTransaction.js'
import CreatePollTransaction from './CreatePollTransaction.js'
import DeployAtTransaction from './DeployAtTransaction.js'
import RewardShareTransaction from './RewardShareTransaction.js'
import RemoveRewardShareTransaction from './RemoveRewardShareTransaction.js'
import UpdateNameTransaction from './UpdateNameTransaction.js'
import UpdateGroupTransaction from './UpdateGroupTransaction.js'
import SellNameTransacion from './SellNameTransacion.js'
import CancelSellNameTransacion from './CancelSellNameTransacion.js'
import BuyNameTransacion from './BuyNameTransacion.js'
import TransferAssetTransaction from './TransferAssetTransaction.js'
import PaymentTransaction from './PaymentTransaction.js';
import ChatTransaction from './ChatTransaction.js';
import GroupChatTransaction from './GroupChatTransaction.js';
import GroupInviteTransaction from './GroupInviteTransaction.js';
import CancelGroupInviteTransaction from './CancelGroupInviteTransaction.js';
import GroupKickTransaction from './GroupKickTransaction.js';
import GroupBanTransaction from './GroupBanTransaction.js';
import CancelGroupBanTransaction from './CancelGroupBanTransaction.js';
import CreateGroupTransaction from './CreateGroupTransaction.js';
import LeaveGroupTransaction from './LeaveGroupTransaction.js';
import JoinGroupTransaction from './JoinGroupTransaction.js';
import AddGroupAdminTransaction from './AddGroupAdminTransaction.js';
import RemoveGroupAdminTransaction from './RemoveGroupAdminTransaction.js';
import RegisterNameTransaction from './RegisterNameTransaction.js';
import VoteOnPollTransaction from './VoteOnPollTransaction.js';
import CreatePollTransaction from './CreatePollTransaction.js';
import DeployAtTransaction from './DeployAtTransaction.js';
import RewardShareTransaction from './RewardShareTransaction.js';
import RemoveRewardShareTransaction from './RemoveRewardShareTransaction.js';
import UpdateNameTransaction from './UpdateNameTransaction.js';
import UpdateGroupTransaction from './UpdateGroupTransaction.js';
import SellNameTransacion from './SellNameTransacion.js';
import CancelSellNameTransacion from './CancelSellNameTransacion.js';
import BuyNameTransacion from './BuyNameTransacion.js';
import TransferAssetTransaction from './TransferAssetTransaction.js';
export const transactionTypes = {
2: PaymentTransaction,
3: RegisterNameTransaction,
4: UpdateNameTransaction,
5: SellNameTransacion,
6: CancelSellNameTransacion,
7: BuyNameTransacion,
8: CreatePollTransaction,
9: VoteOnPollTransaction,
12: TransferAssetTransaction,
16: DeployAtTransaction,
18: ChatTransaction,
181: GroupChatTransaction,
22: CreateGroupTransaction,
23: UpdateGroupTransaction,
24: AddGroupAdminTransaction,
25: RemoveGroupAdminTransaction,
26: GroupBanTransaction,
27: CancelGroupBanTransaction,
28: GroupKickTransaction,
29: GroupInviteTransaction,
30: CancelGroupInviteTransaction,
31: JoinGroupTransaction,
32: LeaveGroupTransaction,
38: RewardShareTransaction,
381: RemoveRewardShareTransaction
}
2: PaymentTransaction,
3: RegisterNameTransaction,
4: UpdateNameTransaction,
5: SellNameTransacion,
6: CancelSellNameTransacion,
7: BuyNameTransacion,
8: CreatePollTransaction,
9: VoteOnPollTransaction,
12: TransferAssetTransaction,
16: DeployAtTransaction,
18: ChatTransaction,
181: GroupChatTransaction,
22: CreateGroupTransaction,
23: UpdateGroupTransaction,
24: AddGroupAdminTransaction,
25: RemoveGroupAdminTransaction,
26: GroupBanTransaction,
27: CancelGroupBanTransaction,
28: GroupKickTransaction,
29: GroupInviteTransaction,
30: CancelGroupInviteTransaction,
31: JoinGroupTransaction,
32: LeaveGroupTransaction,
38: RewardShareTransaction,
381: RemoveRewardShareTransaction,
};
export const createTransaction = (type, keyPair, params) => {
const tx = new transactionTypes[type]()
tx.keyPair = keyPair
Object.keys(params).forEach(param => {
const tx = new transactionTypes[type]();
tx.keyPair = keyPair;
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 => {
if (typeof str !== 'string' || str.length % 4 !== 0) return false;
const base64Regex = /^[A-Za-z0-9+/]*={0,2}$/;
return base64Regex.test(str);
};

View File

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

View File

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

View File

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

View File

@ -1,12 +1,12 @@
export function convertQortalLinks(inputHtml: string) {
// Regular expression to match 'qortal://...' URLs.
// This will stop at the first whitespace, comma, or HTML tag
var regex = /(qortal:\/\/[^\s,<]+)/g;
// Regular expression to match 'qortal://...' URLs.
// This will stop at the first whitespace, comma, or HTML tag
var regex = /(qortal:\/\/[^\s,<]+)/g;
// Replace matches in inputHtml with formatted anchor tag
var outputHtml = inputHtml.replace(regex, function (match) {
return `<a href="${match}" class="qortal-link">${match}</a>`;
});
// Replace matches in inputHtml with formatted anchor tag
var outputHtml = inputHtml.replace(regex, function (match) {
return `<a href="${match}" class="qortal-link">${match}</a>`;
});
return outputHtml;
return outputHtml;
}

View File

@ -1,173 +1,182 @@
// Author: irontiga <irontiga@gmail.com>
import { html, LitElement, css } from 'lit'
import * as WORDLISTS from './wordList'
import { html, LitElement, css } from 'lit';
import * as WORDLISTS from './wordList';
class RandomSentenceGenerator extends LitElement {
static get properties() {
return {
template: { type: String, attribute: 'template' },
parsedString: { type: String },
fetchedWordlistCount: { type: Number, value: 0 },
capitalize: { type: Boolean },
partsOfSpeechMap: { type: Object },
templateEntropy: { type: Number, reflect: true, attribute: 'template-entropy' },
maxWordLength: { type: Number, attribute: 'max-word-length' }
}
}
static get properties() {
return {
template: { type: String, attribute: 'template' },
parsedString: { type: String },
fetchedWordlistCount: { type: Number, value: 0 },
capitalize: { type: Boolean },
partsOfSpeechMap: { type: Object },
templateEntropy: {
type: Number,
reflect: true,
attribute: 'template-entropy',
},
maxWordLength: { type: Number, attribute: 'max-word-length' },
};
}
constructor() {
super()
this.template = 'adjective noun verb adverb.'
this.maxWordLength = 0
this.parsedString = ''
this.fetchedWordlistCount = 0
this.capitalize = true
this.partsOfSpeechMap = {
'noun': 'nouns',
'adverb': 'adverbs',
'adv': 'adverbs',
'verb': 'verbs',
'interjection': 'interjections',
'adjective': 'adjectives',
'adj': 'adjectives',
'verbed': 'verbed'
}
this.partsOfSpeech = Object.keys(this.partsOfSpeechMap)
this._wordlists = WORDLISTS
}
constructor() {
super();
this.template = 'adjective noun verb adverb.';
this.maxWordLength = 0;
this.parsedString = '';
this.fetchedWordlistCount = 0;
this.capitalize = true;
this.partsOfSpeechMap = {
noun: 'nouns',
adverb: 'adverbs',
adv: 'adverbs',
verb: 'verbs',
interjection: 'interjections',
adjective: 'adjectives',
adj: 'adjectives',
verbed: 'verbed',
};
this.partsOfSpeech = Object.keys(this.partsOfSpeechMap);
this._wordlists = WORDLISTS;
}
static styles = css`
static styles = css`
div {
text-align: center;
width: 100%;
background-color: #1f2023;
border-radius: 5px;
padding: 10px;
width: 100%;
background-color: #1f2023;
border-radius: 5px;
padding: 10px;
}
`;
render() {
return html`
<div>${this.parsedString}</div>
`
}
render() {
return html` <div>${this.parsedString}</div> `;
}
firstUpdated() {
// ...
}
updated(changedProperties) {
let regen = false;
firstUpdated() {
// ...
}
if (changedProperties.has('template')) {
regen = true;
}
updated(changedProperties) {
let regen = false
if (changedProperties.has('maxWordLength')) {
console.dir(this.maxWordLength);
if (changedProperties.has('template')) {
regen = true
}
if (this.maxWordLength) {
const wl = { ...this._wordlists };
if (changedProperties.has('maxWordLength')) {
console.dir(this.maxWordLength)
for (const partOfSpeech in this._wordlists) {
if (Array.isArray(this._wordlists[partOfSpeech])) {
wl[partOfSpeech] = this._wordlists[partOfSpeech].filter(
(word) => word.length <= this.maxWordLength
);
}
}
if (this.maxWordLength) {
const wl = { ...this._wordlists }
this._wordlists = wl;
}
for (const partOfSpeech in this._wordlists) {
if (Array.isArray(this._wordlists[partOfSpeech])) {
wl[partOfSpeech] = this._wordlists[partOfSpeech].filter(word => word.length <= this.maxWordLength)
}
}
regen = true;
}
this._wordlists = wl
}
if (regen) this.generate();
}
regen = true
}
_RNG(entropy) {
if (entropy > 1074) {
throw new Error('Javascript can not handle that much entropy!');
}
if (regen) this.generate()
}
let randNum = 0;
_RNG(entropy) {
if (entropy > 1074) {
throw new Error('Javascript can not handle that much entropy!')
}
const crypto = window.crypto || window.msCrypto;
let randNum = 0
if (crypto) {
const entropy256 = Math.ceil(entropy / 8);
const crypto = window.crypto || window.msCrypto
let buffer = new Uint8Array(entropy256);
if (crypto) {
const entropy256 = Math.ceil(entropy / 8)
crypto.getRandomValues(buffer);
let buffer = new Uint8Array(entropy256)
randNum =
buffer.reduce((num, value) => {
return num * value;
}, 1) / Math.pow(256, entropy256);
} else {
console.warn('Secure RNG not found. Using Math.random');
crypto.getRandomValues(buffer)
randNum = Math.random();
}
randNum = buffer.reduce((num, value) => {
return num * value
}, 1) / Math.pow(256, entropy256)
} else {
console.warn('Secure RNG not found. Using Math.random')
return randNum;
}
randNum = Math.random()
}
setRNG(fn) {
this._RNG = fn;
}
return randNum
}
_captitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
setRNG(fn) {
this._RNG = fn
}
getWord(partOfSpeech) {
const words = this._wordlists[this.partsOfSpeechMap[partOfSpeech]];
const requiredEntropy = Math.log(words.length) / Math.log(2);
const index = this._RNG(requiredEntropy) * words.length;
_captitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1)
}
return {
word: words[Math.round(index)],
entropy: words.length,
};
}
getWord(partOfSpeech) {
const words = this._wordlists[this.partsOfSpeechMap[partOfSpeech]]
const requiredEntropy = Math.log(words.length) / Math.log(2)
const index = this._RNG(requiredEntropy) * words.length
generate() {
this.parsedString = this.parse(this.template);
}
return {
word: words[Math.round(index)],
entropy: words.length
}
}
parse(template) {
const split = template.split(/[\s]/g);
generate() {
this.parsedString = this.parse(this.template)
}
let entropy = 1;
parse(template) {
const split = template.split(/[\s]/g)
const final = split.map((word) => {
const lower = word.toLowerCase();
let entropy = 1
this.partsOfSpeech.some((partOfSpeech) => {
const partOfSpeechIndex = lower.indexOf(partOfSpeech); // Check it exists
const nextChar = word.charAt(partOfSpeech.length);
const final = split.map(word => {
const lower = word.toLowerCase()
if (
partOfSpeechIndex === 0 &&
!(nextChar && nextChar.match(/[a-zA-Z]/g) != null)
) {
const replacement = this.getWord(partOfSpeech);
word = replacement.word + word.slice(partOfSpeech.length); // Append the rest of the "word" (punctuation)
entropy = entropy * replacement.entropy;
this.partsOfSpeech.some(partOfSpeech => {
const partOfSpeechIndex = lower.indexOf(partOfSpeech) // Check it exists
const nextChar = word.charAt(partOfSpeech.length)
return true;
}
});
if (partOfSpeechIndex === 0 && !(nextChar && (nextChar.match(/[a-zA-Z]/g) != null))) {
const replacement = this.getWord(partOfSpeech)
word = replacement.word + word.slice(partOfSpeech.length) // Append the rest of the "word" (punctuation)
entropy = entropy * replacement.entropy
return word;
});
return true
}
})
this.templateEntropy = Math.floor(Math.log(entropy) / Math.log(8));
return word
})
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 = {
'are': 'were',
'eat': 'ate',
'go': 'went',
'have': 'had',
'inherit': 'inherited',
'is': 'was',
'run': 'ran',
'sit': 'sat',
'visit': 'visited'
}
are: 'were',
eat: 'ate',
go: 'went',
have: 'had',
inherit: 'inherited',
is: 'was',
run: 'ran',
sit: 'sat',
visit: 'visited',
};
export const getPastTense = (verb, exceptions = EXCEPTIONS) => {
if (exceptions[verb]) {
return exceptions[verb]
}
if (exceptions[verb]) {
return exceptions[verb];
}
if ((/e$/i).test(verb)) {
return verb + 'd'
}
if (/e$/i.test(verb)) {
return verb + 'd';
}
if ((/[aeiou]c$/i).test(verb)) {
return verb + 'ked'
}
if (/[aeiou]c$/i.test(verb)) {
return verb + 'ked';
}
// for american english only
if ((/el$/i).test(verb)) {
return verb + 'ed'
}
// for american english only
if (/el$/i.test(verb)) {
return verb + 'ed';
}
if ((/[aeio][aeiou][dlmnprst]$/).test(verb)) {
return verb + 'ed'
}
if (/[aeio][aeiou][dlmnprst]$/.test(verb)) {
return verb + 'ed';
}
if ((/[aeiou][bdglmnprst]$/i).test(verb)) {
return verb.replace(/(.+[aeiou])([bdglmnprst])/, '$1$2$2ed')
}
if (/[aeiou][bdglmnprst]$/i.test(verb)) {
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) => {
let isAddress = false;
try {
const decodePubKey = Base58.decode(address);