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
super();
this.type = 24;
}
set rGroupId(rGroupId) {
this._rGroupId = rGroupId
this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._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
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)
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
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
super();
this.type = 7;
}
set fee(fee) {
this._fee = fee * QORT_DECIMALS
this._feeBytes = this.constructor.utils.int64ToBytes(this._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)
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)
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
this._recipient =
recipient instanceof Uint8Array
? recipient
: this.constructor.Base58.decode(recipient);
this.theRecipient = recipient;
}
get params() {
const params = super.params
const params = super.params;
params.push(
this._nameLength,
this._nameBytes,
this._sellPriceBytes,
this._recipient,
this._feeBytes
)
return params
);
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
super();
this.type = 27;
}
set rGroupId(rGroupId) {
this._rGroupId = rGroupId
this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._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
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)
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
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
super();
this.type = 30;
}
set rGroupId(rGroupId) {
this._rGroupId = rGroupId
this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._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
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)
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
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
super();
this.type = 6;
}
set fee(fee) {
this._fee = fee * QORT_DECIMALS
this._feeBytes = this.constructor.utils.int64ToBytes(this._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)
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
const params = super.params;
params.push(this._nameLength, this._nameBytes, this._feeBytes);
return params;
}
}

View File

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

View File

@ -1,73 +1,104 @@
// @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
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)
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)
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
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
this._hasChatReference = new Uint8Array(1);
this._hasChatReference[0] = hasChatReference;
}
set chatReference(chatReference) {
this._chatReference = chatReference instanceof Uint8Array ? chatReference : this.constructor.Base58.decode(chatReference)
this._chatReference =
chatReference instanceof Uint8Array
? chatReference
: this.constructor.Base58.decode(chatReference);
}
set message(message) {
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 isEncrypted(isEncrypted) {
this._isEncrypted = new Uint8Array(1)
this._isEncrypted[0] = isEncrypted
this._isEncrypted = new Uint8Array(1);
this._isEncrypted[0] = isEncrypted;
if (isEncrypted === 1) {
const convertedPrivateKey = ed2curve.convertSecretKey(this._keyPair.privateKey)
const convertedPublicKey = ed2curve.convertPublicKey(this._recipientPublicKey)
const sharedSecret = new Uint8Array(32)
nacl.lowlevel.crypto_scalarmult(sharedSecret, convertedPrivateKey, convertedPublicKey)
const 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
this._isText = new Uint8Array(1);
this._isText[0] = isText;
}
get params() {
const params = super.params
const params = super.params;
params.push(
this._proofOfWorkNonce,
this._hasReceipient,
@ -77,16 +108,19 @@ export default class ChatTransaction extends ChatBase {
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)
if (
new Date(this._timestamp).getTime() >=
CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP
) {
params.push(this._hasChatReference);
if (this._hasChatReference[0] == 1) {
params.push(this._chatReference)
params.push(this._chatReference);
}
}
return params
return params;
}
}

View File

@ -1,53 +1,62 @@
// @ts-nocheck
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
super();
this.type = 22;
}
set fee(fee) {
this._fee = fee * QORT_DECIMALS
this._feeBytes = this.constructor.utils.int64ToBytes(this._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)
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)
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
this._rGroupType = new Uint8Array(1);
this._rGroupType[0] = rGroupType;
}
set rGroupApprovalThreshold(rGroupApprovalThreshold) {
this._rGroupApprovalThreshold = new Uint8Array(1)
this._rGroupApprovalThreshold[0] = rGroupApprovalThreshold
this._rGroupApprovalThreshold = new Uint8Array(1);
this._rGroupApprovalThreshold[0] = rGroupApprovalThreshold;
}
set rGroupMinimumBlockDelay(rGroupMinimumBlockDelay) {
this._rGroupMinimumBlockDelayBytes = this.constructor.utils.int32ToBytes(rGroupMinimumBlockDelay)
this._rGroupMinimumBlockDelayBytes = this.constructor.utils.int32ToBytes(
rGroupMinimumBlockDelay
);
}
set rGroupMaximumBlockDelay(rGroupMaximumBlockDelay) {
this._rGroupMaximumBlockDelayBytes = this.constructor.utils.int32ToBytes(rGroupMaximumBlockDelay)
this._rGroupMaximumBlockDelayBytes = this.constructor.utils.int32ToBytes(
rGroupMaximumBlockDelay
);
}
get params() {
const params = super.params
const params = super.params;
params.push(
this._rGroupNameLength,
this._rGroupNameBytes,
@ -58,7 +67,7 @@ export default class CreateGroupTransaction extends TransactionBase {
this._rGroupMinimumBlockDelayBytes,
this._rGroupMaximumBlockDelayBytes,
this._feeBytes
)
return params
);
return params;
}
}

View File

@ -1,57 +1,68 @@
// @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 = []
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 })
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)
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)
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)
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)
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
const optionsArray = rOptions[0].split(', ').map((opt) => opt.trim());
this._pollOptions = optionsArray;
for (let i = 0; i < optionsArray.length; i++) {
this.addOption(optionsArray[i])
this.addOption(optionsArray[i]);
}
this._rNumberOfOptionsBytes = this.constructor.utils.int32ToBytes(optionsArray.length)
this._rNumberOfOptionsBytes = this.constructor.utils.int32ToBytes(
optionsArray.length
);
}
get params() {
const params = super.params
const params = super.params;
params.push(
this._ownerAddress,
this._rPollNameLength,
@ -59,15 +70,15 @@ export default class CreatePollTransaction extends TransactionBase {
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._options[i].length, this._options[i].bytes);
}
params.push(this._feeBytes)
params.push(this._feeBytes);
return params
return params;
}
}

View File

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

View File

@ -1,42 +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 GroupBanTransaction extends TransactionBase {
constructor() {
super()
this.type = 26
super();
this.type = 26;
}
set rGroupId(rGroupId) {
this._rGroupId = rGroupId
this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._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)
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)
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
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)
this._fee = fee * QORT_DECIMALS;
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee);
}
get params() {
const params = super.params
const params = super.params;
params.push(
this._rGroupIdBytes,
this._recipient,
@ -44,7 +50,7 @@ export default class GroupBanTransaction extends TransactionBase {
this._rBanReasonBytes,
this._rBanTimeBytes,
this._feeBytes
)
return params
);
return params;
}
}

View File

@ -1,53 +1,57 @@
// @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
this.type = 18;
this.fee = 0;
}
set proofOfWorkNonce(proofOfWorkNonce) {
this._proofOfWorkNonce = this.constructor.utils.int32ToBytes(proofOfWorkNonce)
this._proofOfWorkNonce =
this.constructor.utils.int32ToBytes(proofOfWorkNonce);
}
set hasReceipient(hasReceipient) {
this._hasReceipient = new Uint8Array(1)
this._hasReceipient[0] = hasReceipient
this._hasReceipient = new Uint8Array(1);
this._hasReceipient[0] = hasReceipient;
}
set message(message) {
this.messageText = message
this.messageText = message;
this._message = this.constructor.utils.stringtoUTF8Array(message)
this._messageLength = this.constructor.utils.int32ToBytes(this._message.length)
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
this._hasChatReference = new Uint8Array(1);
this._hasChatReference[0] = hasChatReference;
}
set chatReference(chatReference) {
this._chatReference = chatReference instanceof Uint8Array ? chatReference : this.constructor.Base58.decode(chatReference)
this._chatReference =
chatReference instanceof Uint8Array
? chatReference
: this.constructor.Base58.decode(chatReference);
}
set isEncrypted(isEncrypted) {
this._isEncrypted = new Uint8Array(1)
this._isEncrypted[0] = isEncrypted
this._isEncrypted = new Uint8Array(1);
this._isEncrypted[0] = isEncrypted;
}
set isText(isText) {
this._isText = new Uint8Array(1)
this._isText[0] = isText
this._isText = new Uint8Array(1);
this._isText[0] = isText;
}
get params() {
const params = super.params
const params = super.params;
params.push(
this._proofOfWorkNonce,
this._hasReceipient,
@ -56,17 +60,20 @@ export default class GroupChatTransaction extends ChatBase {
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)
if (
new Date(this._timestamp).getTime() >=
CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP
) {
params.push(this._hasChatReference);
if (this._hasChatReference[0] == 1) {
params.push(this._chatReference)
params.push(this._chatReference);
}
}
return params
return params;
}
}

View File

@ -1,42 +1,46 @@
// @ts-nocheck
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
super();
this.type = 29;
}
set rGroupId(rGroupId) {
this._rGroupId = rGroupId
this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._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)
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
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)
this._fee = fee * QORT_DECIMALS;
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee);
}
get params() {
const params = super.params
const params = super.params;
params.push(
this._rGroupIdBytes,
this._recipient,
this._rInviteTimeBytes,
this._feeBytes
)
return params
);
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
super();
this.type = 28;
}
set rGroupId(rGroupId) {
this._rGroupId = rGroupId
this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._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)
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
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)
this._fee = fee * QORT_DECIMALS;
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee);
}
get params() {
const params = super.params
const params = super.params;
params.push(
this._rGroupIdBytes,
this._recipient,
this._rBanReasonLength,
this._rBanReasonBytes,
this._feeBytes
)
return params
);
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
super();
this.type = 31;
}
set fee(fee) {
this._fee = fee * QORT_DECIMALS
this._feeBytes = this.constructor.utils.int64ToBytes(this._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)
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)
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
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
super();
this.type = 32;
}
set fee(fee) {
this._fee = fee * QORT_DECIMALS
this._feeBytes = this.constructor.utils.int64ToBytes(this._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)
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)
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
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
super();
this.type = 2;
}
set recipient(recipient) {
this._recipient = recipient instanceof Uint8Array ? recipient : this.constructor.Base58.decode(recipient)
this._recipient =
recipient instanceof Uint8Array
? recipient
: this.constructor.Base58.decode(recipient);
}
set dialogto(dialogto) {
this._dialogto = dialogto
this._dialogto = dialogto;
}
set dialogamount(dialogamount) {
this._dialogamount = dialogamount
this._dialogamount = dialogamount;
}
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);
}
get params() {
const params = super.params
params.push(
this._recipient,
this._amountBytes,
this._feeBytes
)
return 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
super();
this.type = 3;
}
set fee(fee) {
this._fee = fee * QORT_DECIMALS
this._feeBytes = this.constructor.utils.int64ToBytes(this._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)
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)
this.valueText =
value.length === 0 ? 'Registered Name on the Qortal Chain' : value;
this._valueBytes = this.constructor.utils.stringtoUTF8Array(this.valueText);
this._valueLength = this.constructor.utils.int32ToBytes(
this._valueBytes.length
);
}
get params() {
const params = super.params
const params = super.params;
params.push(
this._nameLength,
this._nameBytes,
this._valueLength,
this._valueBytes,
this._feeBytes
)
return params
);
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
super();
this.type = 25;
}
set rGroupId(rGroupId) {
this._rGroupId = rGroupId
this._rGroupIdBytes = this.constructor.utils.int32ToBytes(this._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
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)
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
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
super();
this.type = 38;
}
set rewardShareKeyPairPublicKey(rewardShareKeyPairPublicKey) {
this._rewardShareKeyPairPublicKey = Base58.decode(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)
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
this.fee = _address === recipient ? 0 : 0.01;
} else {
this.fee = _address === recipient ? 0 : 0.001
this.fee = _address === recipient ? 0 : 0.001;
}
}
set percentageShare(share) {
this._percentageShare = share * 100
this._percentageShareBytes = this.constructor.utils.int64ToBytes(this._percentageShare)
this._percentageShare = share * 100;
this._percentageShareBytes = this.constructor.utils.int64ToBytes(
this._percentageShare
);
}
get params() {
const params = super.params
const params = super.params;
params.push(
this._recipient,
this._rewardShareKeyPairPublicKey,
this._percentageShareBytes,
this._feeBytes
)
return params
);
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
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)
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)
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)
nacl.lowlevel.crypto_scalarmult(
sharedSecret,
convertedPrivateKey,
convertedPublicKey
);
this._rewardShareSeed = new Sha256().process(sharedSecret).finish().result
this._base58RewardShareSeed = this.constructor.Base58.encode(this._rewardShareSeed)
this._rewardShareKeyPair = nacl.sign.keyPair.fromSeed(this._rewardShareSeed)
this._rewardShareSeed = new Sha256().process(sharedSecret).finish().result;
this._base58RewardShareSeed = this.constructor.Base58.encode(
this._rewardShareSeed
);
this._rewardShareKeyPair = nacl.sign.keyPair.fromSeed(
this._rewardShareSeed
);
if (new Date(this._timestamp).getTime() >= DYNAMIC_FEE_TIMESTAMP) {
this.fee = (recipientPublicKey === this.constructor.Base58.encode(this._keyPair.publicKey) ? 0 : 0.01)
this.fee =
recipientPublicKey ===
this.constructor.Base58.encode(this._keyPair.publicKey)
? 0
: 0.01;
} else {
this.fee = (recipientPublicKey === this.constructor.Base58.encode(this._keyPair.publicKey) ? 0 : 0.001)
this.fee =
recipientPublicKey ===
this.constructor.Base58.encode(this._keyPair.publicKey)
? 0
: 0.001;
}
}
set recipient(recipient) {
this._recipient = recipient instanceof Uint8Array ? recipient : this.constructor.Base58.decode(recipient)
this._recipient =
recipient instanceof Uint8Array
? recipient
: this.constructor.Base58.decode(recipient);
}
set percentageShare(share) {
this._percentageShare = share * 100
this._percentageShareBytes = this.constructor.utils.int64ToBytes(this._percentageShare)
this._percentageShare = share * 100;
this._percentageShareBytes = this.constructor.utils.int64ToBytes(
this._percentageShare
);
}
get params() {
const params = super.params
const params = super.params;
params.push(
this._recipient,
this._rewardShareKeyPair.publicKey,
this._percentageShareBytes,
this._feeBytes
)
return params
);
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
super();
this.type = 5;
}
set fee(fee) {
this._fee = fee * QORT_DECIMALS
this._feeBytes = this.constructor.utils.int64ToBytes(this._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)
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)
this.showSellPrice = sellPrice;
this._sellPrice = sellPrice * QORT_DECIMALS;
this._sellPriceBytes = this.constructor.utils.int64ToBytes(this._sellPrice);
}
get params() {
const params = super.params
const params = super.params;
params.push(
this._nameLength,
this._nameBytes,
this._sellPriceBytes,
this._feeBytes
)
return params
);
return params;
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,35 +1,37 @@
// @ts-nocheck
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,51 +1,53 @@
// @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
super();
this.type = 23;
}
set fee(fee) {
this._fee = fee * QORT_DECIMALS
this._feeBytes = this.constructor.utils.int64ToBytes(this._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)
this._newOwner =
newOwner instanceof Uint8Array
? newOwner
: this.constructor.Base58.decode(newOwner);
}
set newIsOpen(newIsOpen) {
this._rGroupType = new Uint8Array(1)
this._rGroupType[0] = 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)
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 = new Uint8Array(1);
this._rGroupApprovalThreshold[0] = newApprovalThreshold;
}
set newMinimumBlockDelay(newMinimumBlockDelay) {
this._rGroupMinimumBlockDelayBytes = this.constructor.utils.int32ToBytes(newMinimumBlockDelay)
this._rGroupMinimumBlockDelayBytes =
this.constructor.utils.int32ToBytes(newMinimumBlockDelay);
}
set newMaximumBlockDelay(newMaximumBlockDelay) {
this._rGroupMaximumBlockDelayBytes = this.constructor.utils.int32ToBytes(newMaximumBlockDelay)
this._rGroupMaximumBlockDelayBytes =
this.constructor.utils.int32ToBytes(newMaximumBlockDelay);
}
set _groupId(_groupId){
this._groupBytes = this.constructor.utils.int32ToBytes(_groupId)
set _groupId(_groupId) {
this._groupBytes = this.constructor.utils.int32ToBytes(_groupId);
}
get params() {
const params = super.params
const params = super.params;
params.push(
this._groupBytes,
this._newOwner,
@ -56,7 +58,7 @@ export default class UpdateGroupTransaction extends TransactionBase {
this._rGroupMinimumBlockDelayBytes,
this._rGroupMaximumBlockDelayBytes,
this._feeBytes
)
return params
);
return params;
}
}

View File

@ -1,42 +1,47 @@
// @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
super();
this.type = 4;
}
set fee(fee) {
this._fee = fee * QORT_DECIMALS
this._feeBytes = this.constructor.utils.int64ToBytes(this._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)
this.nameText = name;
this._nameBytes = this.constructor.utils.stringtoUTF8Array(name);
this._nameLength = this.constructor.utils.int32ToBytes(
this._nameBytes.length
);
}
set newName(newName) {
this.newNameText = newName
this._newNameBytes = this.constructor.utils.stringtoUTF8Array(newName)
this._newNameLength = this.constructor.utils.int32ToBytes(this._newNameBytes.length)
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)
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
const params = super.params;
params.push(
this._nameLength,
this._nameBytes,
@ -45,7 +50,7 @@ export default class UpdateNameTransaction extends TransactionBase {
this._newDataLength,
this._newDataBytes,
this._feeBytes
)
return params
);
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
super();
this.type = 9;
}
set fee(fee) {
this._fee = fee * QORT_DECIMALS
this._feeBytes = this.constructor.utils.int64ToBytes(this._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)
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)
this._rOptionIndex = rOptionIndex;
this._rOptionIndexBytes = this.constructor.utils.int32ToBytes(
this._rOptionIndex
);
}
get params() {
const params = super.params
const params = super.params;
params.push(
this._rPollNameLength,
this._rPollNameBytes,
this._rOptionIndexBytes,
this._feeBytes
)
return params
);
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')
throw new Error('Chat Bytes not defined');
}
if (!nonce) {
throw new Error('Nonce not defined')
throw new Error('Nonce not defined');
}
if (!keyPair) {
throw new Error('keyPair not defined')
throw new Error('keyPair not defined');
}
const _nonce = utils.int32ToBytes(nonce)
const _nonce = utils.int32ToBytes(nonce);
if (chatBytes.length === undefined) {
const _chatBytesBuffer = Object.keys(chatBytes).map(function (key) { return chatBytes[key]; })
const _chatBytesBuffer = Object.keys(chatBytes).map(function (key) {
return chatBytes[key];
});
const chatBytesBuffer = new Uint8Array(_chatBytesBuffer)
chatBytesBuffer.set(_nonce, 112)
const 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)
return utils.appendBuffer(chatBytesBuffer, signature);
} else {
const chatBytesBuffer = new Uint8Array(chatBytes)
chatBytesBuffer.set(_nonce, 112)
const chatBytesBuffer = new Uint8Array(chatBytes);
chatBytesBuffer.set(_nonce, 112);
const signature = nacl.sign.detached(chatBytesBuffer, keyPair.privateKey)
const signature = nacl.sign.detached(chatBytesBuffer, keyPair.privateKey);
return utils.appendBuffer(chatBytesBuffer, signature)
return utils.appendBuffer(chatBytesBuffer, signature);
}
}
};

View File

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

View File

@ -1,31 +1,30 @@
// @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,
@ -52,17 +51,15 @@ export const transactionTypes = {
31: JoinGroupTransaction,
32: LeaveGroupTransaction,
38: RewardShareTransaction,
381: RemoveRewardShareTransaction
}
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,19 +5,23 @@ 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) {
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'
noun: 'nouns',
adverb: 'adverbs',
adv: 'adverbs',
verb: 'verbs',
interjection: 'interjections',
adjective: 'adjectives',
adj: 'adjectives',
verbed: 'verbed',
};
let _wordlists = WORDLISTS;
@ -33,7 +37,9 @@ export function generateRandomSentence(template = 'adverb verb noun adjective no
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);
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();
@ -48,7 +54,7 @@ export function generateRandomSentence(template = 'adverb verb noun adjective no
function getWord(partOfSpeech) {
let words = _wordlists[partsOfSpeechMap[partOfSpeech]];
if (maxWordLength) {
words = words.filter(word => word.length <= maxWordLength);
words = words.filter((word) => word.length <= maxWordLength);
}
const requiredEntropy = Math.log(words.length) / Math.log(2);
const index = Math.floor(_RNG(requiredEntropy) * words.length);
@ -56,68 +62,66 @@ export function generateRandomSentence(template = 'adverb verb noun adjective no
}
function parse(template) {
return template.split(/\s+/).map(token => {
return template
.split(/\s+/)
.map((token) => {
const match = token.match(/^(\w+)(.*)$/);
if (!match) return token; // No match, return original token
const [ , partOfSpeech, rest ] = match;
const [, partOfSpeech, rest] = match;
if (partsOfSpeechMap[partOfSpeech]) {
let word = getWord(partOfSpeech);
if (capitalize && token === token[0].toUpperCase() + token.slice(1).toLowerCase()) {
if (
capitalize &&
token === token[0].toUpperCase() + token.slice(1).toLowerCase()
) {
word = _capitalize(word);
}
return word + rest;
}
return token;
}).join(' ');
})
.join(' ');
}
return parse(template);
}
export const createAccount = async(generatedSeedPhrase)=> {
if(!generatedSeedPhrase) throw new Error('No generated seed-phrase')
const threads = doInitWorkers(crypto.kdfThreads)
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 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 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";
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,24 +1,30 @@
// @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
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),
@ -26,6 +32,6 @@ export const generateSaveWalletData = async (wallet, password, kdfThreads) => {
iv: Base58.encode(iv),
version: wallet._walletVersion,
mac: Base58.encode(mac),
kdfThreads
}
}
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]
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'
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

@ -1,7 +1,7 @@
// 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() {
@ -11,30 +11,34 @@ class RandomSentenceGenerator extends LitElement {
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' }
}
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
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
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`
@ -48,126 +52,131 @@ class RandomSentenceGenerator extends LitElement {
`;
render() {
return html`
<div>${this.parsedString}</div>
`
return html` <div>${this.parsedString}</div> `;
}
firstUpdated() {
// ...
}
updated(changedProperties) {
let regen = false
let regen = false;
if (changedProperties.has('template')) {
regen = true
regen = true;
}
if (changedProperties.has('maxWordLength')) {
console.dir(this.maxWordLength)
console.dir(this.maxWordLength);
if (this.maxWordLength) {
const wl = { ...this._wordlists }
const wl = { ...this._wordlists };
for (const partOfSpeech in this._wordlists) {
if (Array.isArray(this._wordlists[partOfSpeech])) {
wl[partOfSpeech] = this._wordlists[partOfSpeech].filter(word => word.length <= this.maxWordLength)
wl[partOfSpeech] = this._wordlists[partOfSpeech].filter(
(word) => word.length <= this.maxWordLength
);
}
}
this._wordlists = wl
this._wordlists = wl;
}
regen = true
regen = true;
}
if (regen) this.generate()
if (regen) this.generate();
}
_RNG(entropy) {
if (entropy > 1074) {
throw new Error('Javascript can not handle that much entropy!')
throw new Error('Javascript can not handle that much entropy!');
}
let randNum = 0
let randNum = 0;
const crypto = window.crypto || window.msCrypto
const crypto = window.crypto || window.msCrypto;
if (crypto) {
const entropy256 = Math.ceil(entropy / 8)
const entropy256 = Math.ceil(entropy / 8);
let buffer = new Uint8Array(entropy256)
let buffer = new Uint8Array(entropy256);
crypto.getRandomValues(buffer)
crypto.getRandomValues(buffer);
randNum = buffer.reduce((num, value) => {
return num * value
}, 1) / Math.pow(256, entropy256)
randNum =
buffer.reduce((num, value) => {
return num * value;
}, 1) / Math.pow(256, entropy256);
} else {
console.warn('Secure RNG not found. Using Math.random')
console.warn('Secure RNG not found. Using Math.random');
randNum = Math.random()
randNum = Math.random();
}
return randNum
return randNum;
}
setRNG(fn) {
this._RNG = fn
this._RNG = fn;
}
_captitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1)
return str.charAt(0).toUpperCase() + str.slice(1);
}
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
const words = this._wordlists[this.partsOfSpeechMap[partOfSpeech]];
const requiredEntropy = Math.log(words.length) / Math.log(2);
const index = this._RNG(requiredEntropy) * words.length;
return {
word: words[Math.round(index)],
entropy: words.length
}
entropy: words.length,
};
}
generate() {
this.parsedString = this.parse(this.template)
this.parsedString = this.parse(this.template);
}
parse(template) {
const split = template.split(/[\s]/g)
const split = template.split(/[\s]/g);
let entropy = 1
let entropy = 1;
const final = split.map(word => {
const lower = word.toLowerCase()
const final = split.map((word) => {
const lower = word.toLowerCase();
this.partsOfSpeech.some(partOfSpeech => {
const partOfSpeechIndex = lower.indexOf(partOfSpeech) // Check it exists
const nextChar = word.charAt(partOfSpeech.length)
this.partsOfSpeech.some((partOfSpeech) => {
const partOfSpeechIndex = lower.indexOf(partOfSpeech); // Check it exists
const nextChar = word.charAt(partOfSpeech.length);
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
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 true
return true;
}
})
});
return word
})
return word;
});
this.templateEntropy = Math.floor(Math.log(entropy) / Math.log(8))
this.templateEntropy = Math.floor(Math.log(entropy) / Math.log(8));
return final.join(' ')
return final.join(' ');
}
}
window.customElements.define('random-sentence-generator', RandomSentenceGenerator)
window.customElements.define(
'random-sentence-generator',
RandomSentenceGenerator
);
export default RandomSentenceGenerator
export default RandomSentenceGenerator;

View File

@ -1,40 +1,40 @@
export const EXCEPTIONS = {
'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]
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'
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);