4
1
mirror of https://github.com/Qortal/qortal-ui.git synced 2025-02-11 09:45:52 +00:00

Remove use strict make api full esm compatible

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

View File

@ -1,9 +1,9 @@
import {Sha256} from 'asmcrypto.js'
import { Sha256 } from 'asmcrypto.js'
import Base58 from './api/deps/Base58'
import Base64 from './api/deps/Base64'
import {base58PublicKeyToAddress} from './api/wallet/base58PublicKeyToAddress'
import {validateAddress} from './api/wallet/validateAddress'
import {decryptChatMessage, decryptChatMessageBase64} from './api/transactions/chat/decryptChatMessage'
import { base58PublicKeyToAddress } from './api/wallet/base58PublicKeyToAddress'
import { validateAddress } from './api/wallet/validateAddress'
import { decryptChatMessage, decryptChatMessageBase64 } from './api/transactions/chat/decryptChatMessage'
import _ from 'lodash'
window.Sha256 = Sha256
@ -15,8 +15,8 @@ window.validateAddress = validateAddress
window.decryptChatMessage = decryptChatMessage
window.decryptChatMessageBase64 = decryptChatMessageBase64
export { initApi, store } from './api_deps.js'
export * from './api/deps/deps.js'
export * from './api/api.js'
export * from './api/registerUsername.js'
export { createWallet } from './api/createWallet.js'
export { initApi, store } from './api_deps'
export * from './api/deps/deps'
export * from './api/api'
export * from './api/registerUsername'
export { createWallet } from './api/createWallet'

View File

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

View File

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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,3 @@
'use strict'
// Qortal TX types
const TX_TYPES = {
1: "Genesis",

View File

@ -1,9 +1,9 @@
import {transactionTypes as transactions} from './transactions/transactions.js'
import Base58 from './deps/Base58.js'
import {request} from './fetch-request'
import signChat from './transactions/chat/signChat.js'
import signArbitrary from './transactions/arbitrary/signArbitrary.js'
import signArbitraryWithFee from './transactions/arbitrary/signArbitraryWithFee.js'
import { transactionTypes as transactions } from './transactions/transactions'
import Base58 from './deps/Base58'
import { request } from './fetch-request'
import signChat from './transactions/chat/signChat'
import signArbitrary from './transactions/arbitrary/signArbitrary'
import signArbitraryWithFee from './transactions/arbitrary/signArbitraryWithFee'
export const createTransaction = (type, keyPair, params) => {
const tx = new transactions[type]()
@ -31,8 +31,8 @@ export const signArbitraryTransaction = (arbitraryBytesBase58, arbitraryBytesFor
return signArbitrary(arbitraryBytesBase58, arbitraryBytesForSigningBase58, nonce, keyPair)
}
export const signArbitraryWithFeeTransaction = (arbitraryBytesBase58, arbitraryBytesForSigningBase58, keyPair) => {
return signArbitraryWithFee(arbitraryBytesBase58, arbitraryBytesForSigningBase58, keyPair)
export const signArbitraryWithFeeTransaction = (arbitraryBytesBase58, arbitraryBytesForSigningBase58, keyPair) => {
return signArbitraryWithFee(arbitraryBytesBase58, arbitraryBytesForSigningBase58, keyPair)
}
// Process Transactions

View File

@ -1,7 +1,7 @@
import {kdf} from './kdf.js'
import PhraseWallet from './PhraseWallet.js'
import Base58 from './deps/Base58.js'
import {decryptStoredWallet} from './decryptStoredWallet.js'
import { kdf } from './kdf'
import PhraseWallet from './PhraseWallet'
import Base58 from './deps/Base58'
import { decryptStoredWallet } from './decryptStoredWallet'
export const createWallet = async (sourceType, source, statusUpdateFn) => {
let version, seed

View File

@ -1,10 +1,10 @@
import Base58 from './deps/Base58.js'
import {kdf} from './kdf.js'
import {AES_CBC, HmacSha512} from 'asmcrypto.js'
import {get, registerTranslateConfig} from '../../core/translate'
import Base58 from './deps/Base58'
import { kdf } from './kdf'
import { AES_CBC, HmacSha512 } from 'asmcrypto.js'
import { get, registerTranslateConfig } from '../../core/translate'
registerTranslateConfig({
loader: lang => fetch(`/language/${lang}.json`).then(res => res.json())
loader: lang => fetch(`/language/${lang}.json`).then(res => res.json())
})
export const decryptStoredWallet = async (password, wallet, statusFn = () => { }) => {

View File

@ -1,10 +1,6 @@
// Generated by CoffeeScript 1.8.0
// == Changed for ES6 modules == //
//(function() {
//var ALPHABET, ALPHABET_MAP, Base58, i;
//const Base58 = (typeof module !== "undefined" && module !== null ? module.exports : void 0) || (window.Base58 = {});
const Base58 = {};
const ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
@ -14,95 +10,92 @@ const ALPHABET_MAP = {};
let i = 0;
while (i < ALPHABET.length) {
ALPHABET_MAP[ALPHABET.charAt(i)] = i;
i++;
ALPHABET_MAP[ALPHABET.charAt(i)] = i;
i++;
}
Base58.encode = function(buffer) {
buffer = new Uint8Array(buffer);
var carry, digits, j;
if (buffer.length === 0) {
return "";
}
i = void 0;
j = void 0;
digits = [0];
i = 0;
while (i < buffer.length) {
j = 0;
while (j < digits.length) {
digits[j] <<= 8;
j++;
}
digits[0] += buffer[i];
carry = 0;
j = 0;
while (j < digits.length) {
digits[j] += carry;
carry = (digits[j] / 58) | 0;
digits[j] %= 58;
++j;
}
while (carry) {
digits.push(carry % 58);
carry = (carry / 58) | 0;
}
i++;
}
i = 0;
while (buffer[i] === 0 && i < buffer.length - 1) {
digits.push(0);
i++;
}
return digits.reverse().map(function(digit) {
return ALPHABET[digit];
}).join("");
Base58.encode = function (buffer) {
buffer = new Uint8Array(buffer);
var carry, digits, j;
if (buffer.length === 0) {
return "";
}
i = void 0;
j = void 0;
digits = [0];
i = 0;
while (i < buffer.length) {
j = 0;
while (j < digits.length) {
digits[j] <<= 8;
j++;
}
digits[0] += buffer[i];
carry = 0;
j = 0;
while (j < digits.length) {
digits[j] += carry;
carry = (digits[j] / 58) | 0;
digits[j] %= 58;
++j;
}
while (carry) {
digits.push(carry % 58);
carry = (carry / 58) | 0;
}
i++;
}
i = 0;
while (buffer[i] === 0 && i < buffer.length - 1) {
digits.push(0);
i++;
}
return digits.reverse().map(function (digit) {
return ALPHABET[digit];
}).join("");
};
Base58.decode = function(string) {
var bytes, c, carry, j;
if (string.length === 0) {
return new (typeof Uint8Array !== "undefined" && Uint8Array !== null ? Uint8Array : Buffer)(0);
}
i = void 0;
j = void 0;
bytes = [0];
i = 0;
while (i < string.length) {
c = string[i];
if (!(c in ALPHABET_MAP)) {
throw "Base58.decode received unacceptable input. Character '" + c + "' is not in the Base58 alphabet.";
}
j = 0;
while (j < bytes.length) {
bytes[j] *= 58;
j++;
}
bytes[0] += ALPHABET_MAP[c];
carry = 0;
j = 0;
while (j < bytes.length) {
bytes[j] += carry;
carry = bytes[j] >> 8;
bytes[j] &= 0xff;
++j;
}
while (carry) {
bytes.push(carry & 0xff);
carry >>= 8;
}
i++;
}
i = 0;
while (string[i] === "1" && i < string.length - 1) {
bytes.push(0);
i++;
}
return new (typeof Uint8Array !== "undefined" && Uint8Array !== null ? Uint8Array : Buffer)(bytes.reverse());
Base58.decode = function (string) {
var bytes, c, carry, j;
if (string.length === 0) {
return new (typeof Uint8Array !== "undefined" && Uint8Array !== null ? Uint8Array : Buffer)(0);
}
i = void 0;
j = void 0;
bytes = [0];
i = 0;
while (i < string.length) {
c = string[i];
if (!(c in ALPHABET_MAP)) {
throw "Base58.decode received unacceptable input. Character '" + c + "' is not in the Base58 alphabet.";
}
j = 0;
while (j < bytes.length) {
bytes[j] *= 58;
j++;
}
bytes[0] += ALPHABET_MAP[c];
carry = 0;
j = 0;
while (j < bytes.length) {
bytes[j] += carry;
carry = bytes[j] >> 8;
bytes[j] &= 0xff;
++j;
}
while (carry) {
bytes.push(carry & 0xff);
carry >>= 8;
}
i++;
}
i = 0;
while (string[i] === "1" && i < string.length - 1) {
bytes.push(0);
i++;
}
return new (typeof Uint8Array !== "undefined" && Uint8Array !== null ? Uint8Array : Buffer)(bytes.reverse());
};
// == Changed for ES6 modules == //
//}).call(this);
export default Base58;
export default Base58;

View File

@ -1,23 +1,18 @@
const Base64 = {};
Base64.decode = function (string) {
const binaryString = atob(string);
const binaryLength = binaryString.length;
const bytes = new Uint8Array(binaryLength);
const binaryString = atob(string);
const binaryLength = binaryString.length;
const bytes = new Uint8Array(binaryLength);
for (let i = 0; i < binaryLength; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
for (let i = 0; i < binaryLength; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
const decoder = new TextDecoder();
const decoder = new TextDecoder();
return decoder.decode(bytes);
};
export default Base64;

File diff suppressed because it is too large Load Diff

View File

@ -1,180 +1,179 @@
// "Generated from Java with JSweet 1.0.0 - http://www.jsweet.org";
// BAD IMPLEMENTATION. BROKEN, BUT MUST KEEP CAUSE OF NETWORK
//const RIPEMD160 = (function () {
// == Convert to ES6 module for export == //
const RIPEMD160 = (function () {
function RIPEMD160() {
this.MDbuf = [];
this.MDbuf[0] = 1732584193;
this.MDbuf[1] = -271733879;
this.MDbuf[2] = -1732584194;
this.MDbuf[3] = 271733878;
this.MDbuf[4] = -1009589776;
this.working = new Int32Array(16);
function RIPEMD160() {
this.MDbuf = [];
this.MDbuf[0] = 1732584193;
this.MDbuf[1] = -271733879;
this.MDbuf[2] = -1732584194;
this.MDbuf[3] = 271733878;
this.MDbuf[4] = -1009589776;
this.working = new Int32Array(16);
this.working_ptr = 0;
this.msglen = 0;
}
RIPEMD160.prototype.reset = function () {
this.MDbuf = [];
this.MDbuf[0] = 1732584193;
this.MDbuf[1] = -271733879;
this.MDbuf[2] = -1732584194;
this.MDbuf[3] = 271733878;
this.MDbuf[4] = -1009589776;
this.working = new Int32Array(16);
this.working_ptr = 0;
this.msglen = 0;
};
RIPEMD160.prototype.compress = function (X) {
var index = 0;
var a;
var b;
var c;
var d;
var e;
var A;
var B;
var C;
var D;
var E;
var temp;
var s;
A = a = this.MDbuf[0];
B = b = this.MDbuf[1];
C = c = this.MDbuf[2];
D = d = this.MDbuf[3];
E = e = this.MDbuf[4];
for (; index < 16; index++) {
temp = a + (b ^ c ^ d) + X[RIPEMD160.IndexArray[0][index]];
a = e;
e = d;
d = (c << 10) | (c >>> 22);
c = b;
s = RIPEMD160.ArgArray[0][index];
b = ((temp << s) | (temp >>> (32 - s))) + a;
temp = A + (B ^ (C | ~D)) + X[RIPEMD160.IndexArray[1][index]] + 1352829926;
A = E;
E = D;
D = (C << 10) | (C >>> 22);
C = B;
s = RIPEMD160.ArgArray[1][index];
B = ((temp << s) | (temp >>> (32 - s))) + A;
}
for (; index < 32; index++) {
temp = a + ((b & c) | (~b & d)) + X[RIPEMD160.IndexArray[0][index]] + 1518500249;
a = e;
e = d;
d = (c << 10) | (c >>> 22);
c = b;
s = RIPEMD160.ArgArray[0][index];
b = ((temp << s) | (temp >>> (32 - s))) + a;
temp = A + ((B & D) | (C & ~D)) + X[RIPEMD160.IndexArray[1][index]] + 1548603684;
A = E;
E = D;
D = (C << 10) | (C >>> 22);
C = B;
s = RIPEMD160.ArgArray[1][index];
B = ((temp << s) | (temp >>> (32 - s))) + A;
}
for (; index < 48; index++) {
temp = a + ((b | ~c) ^ d) + X[RIPEMD160.IndexArray[0][index]] + 1859775393;
a = e;
e = d;
d = (c << 10) | (c >>> 22);
c = b;
s = RIPEMD160.ArgArray[0][index];
b = ((temp << s) | (temp >>> (32 - s))) + a;
temp = A + ((B | ~C) ^ D) + X[RIPEMD160.IndexArray[1][index]] + 1836072691;
A = E;
E = D;
D = (C << 10) | (C >>> 22);
C = B;
s = RIPEMD160.ArgArray[1][index];
B = ((temp << s) | (temp >>> (32 - s))) + A;
}
for (; index < 64; index++) {
temp = a + ((b & d) | (c & ~d)) + X[RIPEMD160.IndexArray[0][index]] + -1894007588;
a = e;
e = d;
d = (c << 10) | (c >>> 22);
c = b;
s = RIPEMD160.ArgArray[0][index];
b = ((temp << s) | (temp >>> (32 - s))) + a;
temp = A + ((B & C) | (~B & D)) + X[RIPEMD160.IndexArray[1][index]] + 2053994217;
A = E;
E = D;
D = (C << 10) | (C >>> 22);
C = B;
s = RIPEMD160.ArgArray[1][index];
B = ((temp << s) | (temp >>> (32 - s))) + A;
}
for (; index < 80; index++) {
temp = a + (b ^ (c | ~d)) + X[RIPEMD160.IndexArray[0][index]] + -1454113458;
a = e;
e = d;
d = (c << 10) | (c >>> 22);
c = b;
s = RIPEMD160.ArgArray[0][index];
b = ((temp << s) | (temp >>> (32 - s))) + a;
temp = A + (B ^ C ^ D) + X[RIPEMD160.IndexArray[1][index]];
A = E;
E = D;
D = (C << 10) | (C >>> 22);
C = B;
s = RIPEMD160.ArgArray[1][index];
B = ((temp << s) | (temp >>> (32 - s))) + A;
}
D += c + this.MDbuf[1];
this.MDbuf[1] = this.MDbuf[2] + d + E;
this.MDbuf[2] = this.MDbuf[3] + e + A;
this.MDbuf[3] = this.MDbuf[4] + a + B;
this.MDbuf[4] = this.MDbuf[0] + b + C;
this.MDbuf[0] = D;
};
RIPEMD160.prototype.MDfinish = function (array, lswlen, mswlen) {
var X = array;
X[(lswlen >> 2) & 15] ^= 1 << (((lswlen & 3) << 3) + 7);
if (((lswlen & 63) > 55)) {
this.compress(X);
for (var i = 0; i < 14; i++) {
X[i] = 0;
}
}
X[14] = lswlen << 3;
X[15] = (lswlen >> 29) | (mswlen << 3);
this.compress(X);
};
RIPEMD160.prototype.update = function (input) {
for (var i = 0; i < input.length; i++) {
this.working[this.working_ptr >> 2] ^= input[i] << ((this.working_ptr & 3) << 3);
this.working_ptr++;
if ((this.working_ptr == 64)) {
this.compress(this.working);
for (var j = 0; j < 16; j++) {
this.working[j] = 0;
}
this.working_ptr = 0;
}
}
this.msglen += input.length;
};
RIPEMD160.prototype.digestBin = function () {
this.MDfinish(this.working, this.msglen, 0);
//var res = new Int8Array();
var res = [];
for (var i = 0; i < 20; i++) {
res[i] = ((this.MDbuf[i >> 2] >>> ((i & 3) << 3)) & 255);
}
return new Uint8Array(res);
};
RIPEMD160.prototype.digest = function (input) {
this.update(new Int8Array(input));
return this.digestBin();
};
RIPEMD160.ArgArray = [[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6], [8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11]];
RIPEMD160.IndexArray = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13], [5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]];
return RIPEMD160;
this.working_ptr = 0;
this.msglen = 0;
}
RIPEMD160.prototype.reset = function () {
this.MDbuf = [];
this.MDbuf[0] = 1732584193;
this.MDbuf[1] = -271733879;
this.MDbuf[2] = -1732584194;
this.MDbuf[3] = 271733878;
this.MDbuf[4] = -1009589776;
this.working = new Int32Array(16);
this.working_ptr = 0;
this.msglen = 0;
};
RIPEMD160.prototype.compress = function (X) {
var index = 0;
var a;
var b;
var c;
var d;
var e;
var A;
var B;
var C;
var D;
var E;
var temp;
var s;
A = a = this.MDbuf[0];
B = b = this.MDbuf[1];
C = c = this.MDbuf[2];
D = d = this.MDbuf[3];
E = e = this.MDbuf[4];
for (; index < 16; index++) {
temp = a + (b ^ c ^ d) + X[RIPEMD160.IndexArray[0][index]];
a = e;
e = d;
d = (c << 10) | (c >>> 22);
c = b;
s = RIPEMD160.ArgArray[0][index];
b = ((temp << s) | (temp >>> (32 - s))) + a;
temp = A + (B ^ (C | ~D)) + X[RIPEMD160.IndexArray[1][index]] + 1352829926;
A = E;
E = D;
D = (C << 10) | (C >>> 22);
C = B;
s = RIPEMD160.ArgArray[1][index];
B = ((temp << s) | (temp >>> (32 - s))) + A;
}
for (; index < 32; index++) {
temp = a + ((b & c) | (~b & d)) + X[RIPEMD160.IndexArray[0][index]] + 1518500249;
a = e;
e = d;
d = (c << 10) | (c >>> 22);
c = b;
s = RIPEMD160.ArgArray[0][index];
b = ((temp << s) | (temp >>> (32 - s))) + a;
temp = A + ((B & D) | (C & ~D)) + X[RIPEMD160.IndexArray[1][index]] + 1548603684;
A = E;
E = D;
D = (C << 10) | (C >>> 22);
C = B;
s = RIPEMD160.ArgArray[1][index];
B = ((temp << s) | (temp >>> (32 - s))) + A;
}
for (; index < 48; index++) {
temp = a + ((b | ~c) ^ d) + X[RIPEMD160.IndexArray[0][index]] + 1859775393;
a = e;
e = d;
d = (c << 10) | (c >>> 22);
c = b;
s = RIPEMD160.ArgArray[0][index];
b = ((temp << s) | (temp >>> (32 - s))) + a;
temp = A + ((B | ~C) ^ D) + X[RIPEMD160.IndexArray[1][index]] + 1836072691;
A = E;
E = D;
D = (C << 10) | (C >>> 22);
C = B;
s = RIPEMD160.ArgArray[1][index];
B = ((temp << s) | (temp >>> (32 - s))) + A;
}
for (; index < 64; index++) {
temp = a + ((b & d) | (c & ~d)) + X[RIPEMD160.IndexArray[0][index]] + -1894007588;
a = e;
e = d;
d = (c << 10) | (c >>> 22);
c = b;
s = RIPEMD160.ArgArray[0][index];
b = ((temp << s) | (temp >>> (32 - s))) + a;
temp = A + ((B & C) | (~B & D)) + X[RIPEMD160.IndexArray[1][index]] + 2053994217;
A = E;
E = D;
D = (C << 10) | (C >>> 22);
C = B;
s = RIPEMD160.ArgArray[1][index];
B = ((temp << s) | (temp >>> (32 - s))) + A;
}
for (; index < 80; index++) {
temp = a + (b ^ (c | ~d)) + X[RIPEMD160.IndexArray[0][index]] + -1454113458;
a = e;
e = d;
d = (c << 10) | (c >>> 22);
c = b;
s = RIPEMD160.ArgArray[0][index];
b = ((temp << s) | (temp >>> (32 - s))) + a;
temp = A + (B ^ C ^ D) + X[RIPEMD160.IndexArray[1][index]];
A = E;
E = D;
D = (C << 10) | (C >>> 22);
C = B;
s = RIPEMD160.ArgArray[1][index];
B = ((temp << s) | (temp >>> (32 - s))) + A;
}
D += c + this.MDbuf[1];
this.MDbuf[1] = this.MDbuf[2] + d + E;
this.MDbuf[2] = this.MDbuf[3] + e + A;
this.MDbuf[3] = this.MDbuf[4] + a + B;
this.MDbuf[4] = this.MDbuf[0] + b + C;
this.MDbuf[0] = D;
};
RIPEMD160.prototype.MDfinish = function (array, lswlen, mswlen) {
var X = array;
X[(lswlen >> 2) & 15] ^= 1 << (((lswlen & 3) << 3) + 7);
if (((lswlen & 63) > 55)) {
this.compress(X);
for (var i = 0; i < 14; i++) {
X[i] = 0;
}
}
X[14] = lswlen << 3;
X[15] = (lswlen >> 29) | (mswlen << 3);
this.compress(X);
};
RIPEMD160.prototype.update = function (input) {
for (var i = 0; i < input.length; i++) {
this.working[this.working_ptr >> 2] ^= input[i] << ((this.working_ptr & 3) << 3);
this.working_ptr++;
if ((this.working_ptr == 64)) {
this.compress(this.working);
for (var j = 0; j < 16; j++) {
this.working[j] = 0;
}
this.working_ptr = 0;
}
}
this.msglen += input.length;
};
RIPEMD160.prototype.digestBin = function () {
this.MDfinish(this.working, this.msglen, 0);
//var res = new Int8Array();
var res = [];
for (var i = 0; i < 20; i++) {
res[i] = ((this.MDbuf[i >> 2] >>> ((i & 3) << 3)) & 255);
}
return new Uint8Array(res);
};
RIPEMD160.prototype.digest = function (input) {
this.update(new Int8Array(input));
return this.digestBin();
};
RIPEMD160.ArgArray = [[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6], [8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11]];
RIPEMD160.IndexArray = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13], [5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]];
return RIPEMD160;
})();
export default RIPEMD160

View File

@ -1,3 +1,2 @@
export { default as Base58 } from './Base58.js'
export { default as utils } from './utils.js'
export { default as Base58 } from './Base58'
export { default as utils } from './utils'

View File

@ -10,255 +10,239 @@
Change to es6 import/export
*/
import nacl from './nacl-fast.js'
import nacl from './nacl-fast'
// (function(root, f) {
// 'use strict';
// if (typeof module !== 'undefined' && module.exports) module.exports = f(require('tweetnacl'));
// else root.ed2curve = f(root.nacl);
// }(this, function(nacl) {
// 'use strict';
// if (!nacl) throw new Error('tweetnacl not loaded');
// -- Operations copied from TweetNaCl.js. --
// -- Operations copied from TweetNaCl.js. --
var gf = function (init) {
var i, r = new Float64Array(16);
if (init) for (i = 0; i < init.length; i++) r[i] = init[i];
return r;
};
var gf = function(init) {
var i, r = new Float64Array(16);
if (init) for (i = 0; i < init.length; i++) r[i] = init[i];
return r;
};
var gf0 = gf(),
gf1 = gf([1]),
D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]),
I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]);
var gf0 = gf(),
gf1 = gf([1]),
D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]),
I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]);
function car25519(o) {
var c;
var i;
for (i = 0; i < 16; i++) {
o[i] += 65536;
c = Math.floor(o[i] / 65536);
o[(i+1)*(i<15?1:0)] += c - 1 + 37 * (c-1) * (i===15?1:0);
o[i] -= (c * 65536);
}
}
function sel25519(p, q, b) {
var t, c = ~(b-1);
for (var i = 0; i < 16; i++) {
t = c & (p[i] ^ q[i]);
p[i] ^= t;
q[i] ^= t;
}
}
function unpack25519(o, n) {
var i;
for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8);
o[15] &= 0x7fff;
}
// addition
function A(o, a, b) {
var i;
for (i = 0; i < 16; i++) o[i] = (a[i] + b[i])|0;
}
// subtraction
function Z(o, a, b) {
var i;
for (i = 0; i < 16; i++) o[i] = (a[i] - b[i])|0;
}
// multiplication
function M(o, a, b) {
var i, j, t = new Float64Array(31);
for (i = 0; i < 31; i++) t[i] = 0;
for (i = 0; i < 16; i++) {
for (j = 0; j < 16; j++) {
t[i+j] += a[i] * b[j];
}
}
for (i = 0; i < 15; i++) {
t[i] += 38 * t[i+16];
}
for (i = 0; i < 16; i++) o[i] = t[i];
car25519(o);
car25519(o);
}
// squaring
function S(o, a) {
M(o, a, a);
}
// inversion
function inv25519(o, i) {
var c = gf();
var a;
for (a = 0; a < 16; a++) c[a] = i[a];
for (a = 253; a >= 0; a--) {
S(c, c);
if(a !== 2 && a !== 4) M(c, c, i);
}
for (a = 0; a < 16; a++) o[a] = c[a];
}
function pack25519(o, n) {
var i, j, b;
var m = gf(), t = gf();
for (i = 0; i < 16; i++) t[i] = n[i];
car25519(t);
car25519(t);
car25519(t);
for (j = 0; j < 2; j++) {
m[0] = t[0] - 0xffed;
for (i = 1; i < 15; i++) {
m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1);
m[i-1] &= 0xffff;
}
m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1);
b = (m[15]>>16) & 1;
m[14] &= 0xffff;
sel25519(t, m, 1-b);
}
for (i = 0; i < 16; i++) {
o[2*i] = t[i] & 0xff;
o[2*i+1] = t[i] >> 8;
}
}
function par25519(a) {
var d = new Uint8Array(32);
pack25519(d, a);
return d[0] & 1;
}
function vn(x, xi, y, yi, n) {
var i, d = 0;
for (i = 0; i < n; i++) d |= x[xi + i] ^ y[yi + i];
return (1 & ((d - 1) >>> 8)) - 1;
}
function crypto_verify_32(x, xi, y, yi) {
return vn(x, xi, y, yi, 32);
}
function neq25519(a, b) {
var c = new Uint8Array(32), d = new Uint8Array(32);
pack25519(c, a);
pack25519(d, b);
return crypto_verify_32(c, 0, d, 0);
}
function pow2523(o, i) {
var c = gf();
var a;
for (a = 0; a < 16; a++) c[a] = i[a];
for (a = 250; a >= 0; a--) {
S(c, c);
if (a !== 1) M(c, c, i);
}
for (a = 0; a < 16; a++) o[a] = c[a];
}
function set25519(r, a) {
var i;
for (i = 0; i < 16; i++) r[i] = a[i] | 0;
}
function unpackneg(r, p) {
var t = gf(), chk = gf(), num = gf(),
den = gf(), den2 = gf(), den4 = gf(),
den6 = gf();
set25519(r[2], gf1);
unpack25519(r[1], p);
S(num, r[1]);
M(den, num, D);
Z(num, num, r[2]);
A(den, r[2], den);
S(den2, den);
S(den4, den2);
M(den6, den4, den2);
M(t, den6, num);
M(t, t, den);
pow2523(t, t);
M(t, t, num);
M(t, t, den);
M(t, t, den);
M(r[0], t, den);
S(chk, r[0]);
M(chk, chk, den);
if (neq25519(chk, num)) M(r[0], r[0], I);
S(chk, r[0]);
M(chk, chk, den);
if (neq25519(chk, num)) return -1;
if (par25519(r[0]) === (p[31] >> 7)) Z(r[0], gf0, r[0]);
M(r[3], r[0], r[1]);
return 0;
}
// ----
// Converts Ed25519 public key to Curve25519 public key.
// montgomeryX = (edwardsY + 1)*inverse(1 - edwardsY) mod p
function convertPublicKey(pk) {
var z = new Uint8Array(32),
q = [gf(), gf(), gf(), gf()],
a = gf(), b = gf();
if (unpackneg(q, pk)) return null; // reject invalid key
var y = q[1];
A(a, gf1, y);
Z(b, gf1, y);
inv25519(b, b);
M(a, a, b);
pack25519(z, a);
return z;
}
// Converts Ed25519 secret key to Curve25519 secret key.
function convertSecretKey(sk) {
var d = new Uint8Array(64), o = new Uint8Array(32), i;
nacl.lowlevel.crypto_hash(d, sk, 32);
d[0] &= 248;
d[31] &= 127;
d[31] |= 64;
for (i = 0; i < 32; i++) o[i] = d[i];
for (i = 0; i < 64; i++) d[i] = 0;
return o;
}
function convertKeyPair(edKeyPair) {
var publicKey = convertPublicKey(edKeyPair.publicKey);
if (!publicKey) return null;
return {
publicKey: publicKey,
secretKey: convertSecretKey(edKeyPair.secretKey)
};
}
// return {
// convertPublicKey: convertPublicKey,
// convertSecretKey: convertSecretKey,
// convertKeyPair: convertKeyPair,
// };
export default {
convertPublicKey: convertPublicKey,
convertSecretKey: convertSecretKey,
convertKeyPair: convertKeyPair,
function car25519(o) {
var c;
var i;
for (i = 0; i < 16; i++) {
o[i] += 65536;
c = Math.floor(o[i] / 65536);
o[(i + 1) * (i < 15 ? 1 : 0)] += c - 1 + 37 * (c - 1) * (i === 15 ? 1 : 0);
o[i] -= (c * 65536);
}
}
// }));
function sel25519(p, q, b) {
var t, c = ~(b - 1);
for (var i = 0; i < 16; i++) {
t = c & (p[i] ^ q[i]);
p[i] ^= t;
q[i] ^= t;
}
}
function unpack25519(o, n) {
var i;
for (i = 0; i < 16; i++) o[i] = n[2 * i] + (n[2 * i + 1] << 8);
o[15] &= 0x7fff;
}
// addition
function A(o, a, b) {
var i;
for (i = 0; i < 16; i++) o[i] = (a[i] + b[i]) | 0;
}
// subtraction
function Z(o, a, b) {
var i;
for (i = 0; i < 16; i++) o[i] = (a[i] - b[i]) | 0;
}
// multiplication
function M(o, a, b) {
var i, j, t = new Float64Array(31);
for (i = 0; i < 31; i++) t[i] = 0;
for (i = 0; i < 16; i++) {
for (j = 0; j < 16; j++) {
t[i + j] += a[i] * b[j];
}
}
for (i = 0; i < 15; i++) {
t[i] += 38 * t[i + 16];
}
for (i = 0; i < 16; i++) o[i] = t[i];
car25519(o);
car25519(o);
}
// squaring
function S(o, a) {
M(o, a, a);
}
// inversion
function inv25519(o, i) {
var c = gf();
var a;
for (a = 0; a < 16; a++) c[a] = i[a];
for (a = 253; a >= 0; a--) {
S(c, c);
if (a !== 2 && a !== 4) M(c, c, i);
}
for (a = 0; a < 16; a++) o[a] = c[a];
}
function pack25519(o, n) {
var i, j, b;
var m = gf(), t = gf();
for (i = 0; i < 16; i++) t[i] = n[i];
car25519(t);
car25519(t);
car25519(t);
for (j = 0; j < 2; j++) {
m[0] = t[0] - 0xffed;
for (i = 1; i < 15; i++) {
m[i] = t[i] - 0xffff - ((m[i - 1] >> 16) & 1);
m[i - 1] &= 0xffff;
}
m[15] = t[15] - 0x7fff - ((m[14] >> 16) & 1);
b = (m[15] >> 16) & 1;
m[14] &= 0xffff;
sel25519(t, m, 1 - b);
}
for (i = 0; i < 16; i++) {
o[2 * i] = t[i] & 0xff;
o[2 * i + 1] = t[i] >> 8;
}
}
function par25519(a) {
var d = new Uint8Array(32);
pack25519(d, a);
return d[0] & 1;
}
function vn(x, xi, y, yi, n) {
var i, d = 0;
for (i = 0; i < n; i++) d |= x[xi + i] ^ y[yi + i];
return (1 & ((d - 1) >>> 8)) - 1;
}
function crypto_verify_32(x, xi, y, yi) {
return vn(x, xi, y, yi, 32);
}
function neq25519(a, b) {
var c = new Uint8Array(32), d = new Uint8Array(32);
pack25519(c, a);
pack25519(d, b);
return crypto_verify_32(c, 0, d, 0);
}
function pow2523(o, i) {
var c = gf();
var a;
for (a = 0; a < 16; a++) c[a] = i[a];
for (a = 250; a >= 0; a--) {
S(c, c);
if (a !== 1) M(c, c, i);
}
for (a = 0; a < 16; a++) o[a] = c[a];
}
function set25519(r, a) {
var i;
for (i = 0; i < 16; i++) r[i] = a[i] | 0;
}
function unpackneg(r, p) {
var t = gf(), chk = gf(), num = gf(),
den = gf(), den2 = gf(), den4 = gf(),
den6 = gf();
set25519(r[2], gf1);
unpack25519(r[1], p);
S(num, r[1]);
M(den, num, D);
Z(num, num, r[2]);
A(den, r[2], den);
S(den2, den);
S(den4, den2);
M(den6, den4, den2);
M(t, den6, num);
M(t, t, den);
pow2523(t, t);
M(t, t, num);
M(t, t, den);
M(t, t, den);
M(r[0], t, den);
S(chk, r[0]);
M(chk, chk, den);
if (neq25519(chk, num)) M(r[0], r[0], I);
S(chk, r[0]);
M(chk, chk, den);
if (neq25519(chk, num)) return -1;
if (par25519(r[0]) === (p[31] >> 7)) Z(r[0], gf0, r[0]);
M(r[3], r[0], r[1]);
return 0;
}
// ----
// Converts Ed25519 public key to Curve25519 public key.
// montgomeryX = (edwardsY + 1)*inverse(1 - edwardsY) mod p
function convertPublicKey(pk) {
var z = new Uint8Array(32),
q = [gf(), gf(), gf(), gf()],
a = gf(), b = gf();
if (unpackneg(q, pk)) return null; // reject invalid key
var y = q[1];
A(a, gf1, y);
Z(b, gf1, y);
inv25519(b, b);
M(a, a, b);
pack25519(z, a);
return z;
}
// Converts Ed25519 secret key to Curve25519 secret key.
function convertSecretKey(sk) {
var d = new Uint8Array(64), o = new Uint8Array(32), i;
nacl.lowlevel.crypto_hash(d, sk, 32);
d[0] &= 248;
d[31] &= 127;
d[31] |= 64;
for (i = 0; i < 32; i++) o[i] = d[i];
for (i = 0; i < 64; i++) d[i] = 0;
return o;
}
function convertKeyPair(edKeyPair) {
var publicKey = convertPublicKey(edKeyPair.publicKey);
if (!publicKey) return null;
return {
publicKey: publicKey,
secretKey: convertSecretKey(edKeyPair.secretKey)
};
}
export default {
convertPublicKey: convertPublicKey,
convertSecretKey: convertSecretKey,
convertKeyPair: convertKeyPair,
}

File diff suppressed because it is too large Load Diff

View File

@ -26,9 +26,8 @@ const TYPES = {
MESSAGE_TRANSACTION: 17
};
function getKeyPairFromSeed(seed, returnBase58)
{
if(typeof(seed) == "string") {
function getKeyPairFromSeed(seed, returnBase58) {
if (typeof (seed) == "string") {
seed = new Uint8Array(Base58.decode(seed));
}
@ -36,7 +35,7 @@ function getKeyPairFromSeed(seed, returnBase58)
var base58privateKey = Base58.encode(keyPair.secretKey);
var base58publicKey = Base58.encode(keyPair.publicKey);
if(returnBase58) {
if (returnBase58) {
return {
privateKey: Base58.encode(keyPair.secretKey),
publicKey: Base58.encode(keyPair.publicKey)
@ -51,16 +50,16 @@ function getKeyPairFromSeed(seed, returnBase58)
function stringtoUTF8Array(message) {
if (typeof message == 'string') {
var s = unescape(encodeURIComponent(message)); // UTF-8
message = new Uint8Array(s.length);
for (var i = 0; i < s.length; i++) {
var s = unescape(encodeURIComponent(message)); // UTF-8
message = new Uint8Array(s.length);
for (var i = 0; i < s.length; i++) {
message[i] = s.charCodeAt(i) & 0xff;
}
}
return message;
}
function int32ToBytes (word) {
function int32ToBytes(word) {
var byteArray = [];
for (var b = 0; b < 32; b += 8) {
byteArray.push((word >>> (24 - b % 32)) & 0xFF);
@ -68,20 +67,20 @@ function int32ToBytes (word) {
return byteArray;
}
function int64ToBytes (int64) {
// we want to represent the input as a 8-bytes array
var byteArray = [0, 0, 0, 0, 0, 0, 0, 0];
function int64ToBytes(int64) {
// we want to represent the input as a 8-bytes array
var byteArray = [0, 0, 0, 0, 0, 0, 0, 0];
for ( var index = 0; index < byteArray.length; index ++ ) {
var byte = int64 & 0xff;
byteArray [ byteArray.length - index - 1 ] = byte;
int64 = (int64 - byte) / 256 ;
}
for (var index = 0; index < byteArray.length; index++) {
var byte = int64 & 0xff;
byteArray[byteArray.length - index - 1] = byte;
int64 = (int64 - byte) / 256;
}
return byteArray;
return byteArray;
}
function appendBuffer (buffer1, buffer2) {
function appendBuffer(buffer1, buffer2) {
buffer1 = new Uint8Array(buffer1);
buffer2 = new Uint8Array(buffer2);
var tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength);
@ -90,21 +89,18 @@ function appendBuffer (buffer1, buffer2) {
return tmp;
}
function equal (buf1, buf2)
{
if (buf1.byteLength != buf2.byteLength) return false;
var dv1 = new Uint8Array(buf1);
var dv2 = new Uint8Array(buf2);
for (var i = 0; i != buf1.byteLength; i++)
{
if (dv1[i] != dv2[i]) return false;
}
return true;
function equal(buf1, buf2) {
if (buf1.byteLength != buf2.byteLength) return false;
var dv1 = new Uint8Array(buf1);
var dv2 = new Uint8Array(buf2);
for (var i = 0; i != buf1.byteLength; i++) {
if (dv1[i] != dv2[i]) return false;
}
return true;
}
function generateAccountSeed(seed, nonce, returnBase58)
{
if(typeof(seed) == "string") {
function generateAccountSeed(seed, nonce, returnBase58) {
if (typeof (seed) == "string") {
seed = Base58.decode(seed);
}
@ -116,7 +112,7 @@ function generateAccountSeed(seed, nonce, returnBase58)
resultSeed = appendBuffer(resultSeed, seed);
resultSeed = appendBuffer(resultSeed, nonceBytes);
if(returnBase58) {
if (returnBase58) {
return Base58.encode(SHA256.digest(SHA256.digest(resultSeed)));
} else {
return new SHA256.digest(SHA256.digest(resultSeed));
@ -124,11 +120,10 @@ function generateAccountSeed(seed, nonce, returnBase58)
}
function getAccountAddressFromPublicKey(publicKey)
{
function getAccountAddressFromPublicKey(publicKey) {
var ADDRESS_VERSION = 58; // Q
if(typeof(publicKey) == "string") {
if (typeof (publicKey) == "string") {
publicKey = Base58.decode(publicKey);
}
@ -150,13 +145,12 @@ function getAccountAddressFromPublicKey(publicKey)
return Base58.encode(addressArray);
}
function getAccountAddressType(address)
{
function getAccountAddressType(address) {
try {
var ADDRESS_VERSION = 58; // Q
var AT_ADDRESS_VERSION = 23; // A
if(typeof(address) == "string") {
if (typeof (address) == "string") {
address = Base58.decode(address);
}
@ -166,14 +160,11 @@ function getAccountAddressType(address)
var checkSumTwo = SHA256.digest(SHA256.digest(addressWitoutChecksum));
checkSumTwo = checkSumTwo.subarray(0, 4);
if (equal(checkSum, checkSumTwo))
{
if(address[0] == ADDRESS_VERSION)
{
if (equal(checkSum, checkSumTwo)) {
if (address[0] == ADDRESS_VERSION) {
return "standard";
}
if(address[0] == AT_ADDRESS_VERSION)
{
if (address[0] == AT_ADDRESS_VERSION) {
return "at";
}
}
@ -185,8 +176,7 @@ function getAccountAddressType(address)
}
}
function isValidAddress(address)
{
function isValidAddress(address) {
return (getAccountAddressType(address) != "invalid");
}
@ -307,8 +297,8 @@ function generateSignatureRegisterNameTransaction(keyPair, lastReference, owner,
}
function generateRegisterNameTransaction(keyPair, lastReference, owner, name, value, fee, timestamp, signature) {
return appendBuffer( generateRegisterNameTransactionBase(keyPair.publicKey, lastReference, owner, name, value, fee, timestamp),
signature );
return appendBuffer(generateRegisterNameTransactionBase(keyPair.publicKey, lastReference, owner, name, value, fee, timestamp),
signature);
}
function generateRegisterNameTransactionBase(publicKey, lastReference, owner, name, value, fee, timestamp) {
@ -333,4 +323,4 @@ function generateRegisterNameTransactionBase(publicKey, lastReference, owner, na
data = appendBuffer(data, feeBytes);
return data;
}
}

View File

@ -1,5 +1,7 @@
// Extracted from https://github.com/crypto-browserify/ripemd160
const ARRAY16 = new Array(16);
const zl = initU8Array([
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,

View File

@ -3,140 +3,139 @@
const SHA256 = {};
SHA256.K = [
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b,
0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01,
0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7,
0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152,
0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc,
0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819,
0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08,
0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f,
0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b,
0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01,
0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7,
0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152,
0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc,
0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819,
0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08,
0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f,
0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
];
// The digest function returns the hash value (digest)
// as a 32 byte (typed) array.
// message: the string or byte array to hash
SHA256.digest = function(message) {
var h0 = 0x6a09e667;
var h1 = 0xbb67ae85;
var h2 = 0x3c6ef372;
var h3 = 0xa54ff53a;
var h4 = 0x510e527f;
var h5 = 0x9b05688c;
var h6 = 0x1f83d9ab;
var h7 = 0x5be0cd19;
var K = SHA256.K;
if (typeof message == 'string') {
var s = unescape(encodeURIComponent(message)); // UTF-8
message = new Uint8Array(s.length);
for (var i = 0; i < s.length; i++) {
message[i] = s.charCodeAt(i) & 0xff;
}
}
var length = message.length;
var byteLength = Math.floor((length + 72) / 64) * 64;
var wordLength = byteLength / 4;
var bitLength = length * 8;
var m = new Uint8Array(byteLength);
m.set(message);
m[length] = 0x80;
m[byteLength - 4] = bitLength >>> 24;
m[byteLength - 3] = (bitLength >>> 16) & 0xff;
m[byteLength - 2] = (bitLength >>> 8) & 0xff;
m[byteLength - 1] = bitLength & 0xff;
var words = new Int32Array(wordLength);
var byteIndex = 0;
for (var i = 0; i < words.length; i++) {
var word = m[byteIndex++] << 24;
word |= m[byteIndex++] << 16;
word |= m[byteIndex++] << 8;
word |= m[byteIndex++];
words[i] = word;
}
var w = new Int32Array(64);
for (var j = 0; j < wordLength; j += 16) {
for (i = 0; i < 16; i++) {
w[i] = words[j + i];
}
for (i = 16; i < 64; i++) {
var v = w[i - 15];
var s0 = (v >>> 7) | (v << 25);
s0 ^= (v >>> 18) | (v << 14);
s0 ^= (v >>> 3);
v = w[i - 2];
var s1 = (v >>> 17) | (v << 15);
s1 ^= (v >>> 19) | (v << 13);
s1 ^= (v >>> 10);
w[i] = (w[i - 16] + s0 + w[i - 7] + s1) & 0xffffffff;
}
var a = h0;
var b = h1;
var c = h2;
var d = h3;
var e = h4;
var f = h5;
var g = h6;
var h = h7;
for (i = 0; i < 64; i++) {
s1 = (e >>> 6) | (e << 26);
s1 ^= (e >>> 11) | (e << 21);
s1 ^= (e >>> 25) | (e << 7);
var ch = (e & f) ^ (~e & g);
var temp1 = (h + s1 + ch + K[i] + w[i]) & 0xffffffff;
s0 = (a >>> 2) | (a << 30);
s0 ^= (a >>> 13) | (a << 19);
s0 ^= (a >>> 22) | (a << 10);
var maj = (a & b) ^ (a & c) ^ (b & c);
var temp2 = (s0 + maj) & 0xffffffff;
h = g
g = f
f = e
e = (d + temp1) & 0xffffffff;
d = c;
c = b;
b = a;
a = (temp1 + temp2) & 0xffffffff;
}
h0 = (h0 + a) & 0xffffffff;
h1 = (h1 + b) & 0xffffffff;
h2 = (h2 + c) & 0xffffffff;
h3 = (h3 + d) & 0xffffffff;
h4 = (h4 + e) & 0xffffffff;
h5 = (h5 + f) & 0xffffffff;
h6 = (h6 + g) & 0xffffffff;
h7 = (h7 + h) & 0xffffffff;
}
var hash = new Uint8Array(32);
for (var i = 0; i < 4; i++) {
hash[i] = (h0 >>> (8 * (3 - i))) & 0xff;
hash[i + 4] = (h1 >>> (8 * (3 - i))) & 0xff;
hash[i + 8] = (h2 >>> (8 * (3 - i))) & 0xff;
hash[i + 12] = (h3 >>> (8 * (3 - i))) & 0xff;
hash[i + 16] = (h4 >>> (8 * (3 - i))) & 0xff;
hash[i + 20] = (h5 >>> (8 * (3 - i))) & 0xff;
hash[i + 24] = (h6 >>> (8 * (3 - i))) & 0xff;
hash[i + 28] = (h7 >>> (8 * (3 - i))) & 0xff;
}
return hash;
}
SHA256.digest = function (message) {
var h0 = 0x6a09e667;
var h1 = 0xbb67ae85;
var h2 = 0x3c6ef372;
var h3 = 0xa54ff53a;
var h4 = 0x510e527f;
var h5 = 0x9b05688c;
var h6 = 0x1f83d9ab;
var h7 = 0x5be0cd19;
var K = SHA256.K;
if (typeof message == 'string') {
var s = unescape(encodeURIComponent(message)); // UTF-8
message = new Uint8Array(s.length);
for (var i = 0; i < s.length; i++) {
message[i] = s.charCodeAt(i) & 0xff;
}
}
var length = message.length;
var byteLength = Math.floor((length + 72) / 64) * 64;
var wordLength = byteLength / 4;
var bitLength = length * 8;
var m = new Uint8Array(byteLength);
m.set(message);
m[length] = 0x80;
m[byteLength - 4] = bitLength >>> 24;
m[byteLength - 3] = (bitLength >>> 16) & 0xff;
m[byteLength - 2] = (bitLength >>> 8) & 0xff;
m[byteLength - 1] = bitLength & 0xff;
var words = new Int32Array(wordLength);
var byteIndex = 0;
for (var i = 0; i < words.length; i++) {
var word = m[byteIndex++] << 24;
word |= m[byteIndex++] << 16;
word |= m[byteIndex++] << 8;
word |= m[byteIndex++];
words[i] = word;
}
var w = new Int32Array(64);
for (var j = 0; j < wordLength; j += 16) {
for (i = 0; i < 16; i++) {
w[i] = words[j + i];
}
for (i = 16; i < 64; i++) {
var v = w[i - 15];
var s0 = (v >>> 7) | (v << 25);
s0 ^= (v >>> 18) | (v << 14);
s0 ^= (v >>> 3);
v = w[i - 2];
var s1 = (v >>> 17) | (v << 15);
s1 ^= (v >>> 19) | (v << 13);
s1 ^= (v >>> 10);
w[i] = (w[i - 16] + s0 + w[i - 7] + s1) & 0xffffffff;
}
var a = h0;
var b = h1;
var c = h2;
var d = h3;
var e = h4;
var f = h5;
var g = h6;
var h = h7;
for (i = 0; i < 64; i++) {
s1 = (e >>> 6) | (e << 26);
s1 ^= (e >>> 11) | (e << 21);
s1 ^= (e >>> 25) | (e << 7);
var ch = (e & f) ^ (~e & g);
var temp1 = (h + s1 + ch + K[i] + w[i]) & 0xffffffff;
s0 = (a >>> 2) | (a << 30);
s0 ^= (a >>> 13) | (a << 19);
s0 ^= (a >>> 22) | (a << 10);
var maj = (a & b) ^ (a & c) ^ (b & c);
var temp2 = (s0 + maj) & 0xffffffff;
h = g
g = f
f = e
e = (d + temp1) & 0xffffffff;
d = c;
c = b;
b = a;
a = (temp1 + temp2) & 0xffffffff;
}
h0 = (h0 + a) & 0xffffffff;
h1 = (h1 + b) & 0xffffffff;
h2 = (h2 + c) & 0xffffffff;
h3 = (h3 + d) & 0xffffffff;
h4 = (h4 + e) & 0xffffffff;
h5 = (h5 + f) & 0xffffffff;
h6 = (h6 + g) & 0xffffffff;
h7 = (h7 + h) & 0xffffffff;
}
var hash = new Uint8Array(32);
for (var i = 0; i < 4; i++) {
hash[i] = (h0 >>> (8 * (3 - i))) & 0xff;
hash[i + 4] = (h1 >>> (8 * (3 - i))) & 0xff;
hash[i + 8] = (h2 >>> (8 * (3 - i))) & 0xff;
hash[i + 12] = (h3 >>> (8 * (3 - i))) & 0xff;
hash[i + 16] = (h4 >>> (8 * (3 - i))) & 0xff;
hash[i + 20] = (h5 >>> (8 * (3 - i))) & 0xff;
hash[i + 24] = (h6 >>> (8 * (3 - i))) & 0xff;
hash[i + 28] = (h7 >>> (8 * (3 - i))) & 0xff;
}
return hash;
}
// The hash function returns the hash value as a hex string.
// message: the string or byte array to hash
SHA256.hash = function(message) {
var digest = SHA256.digest(message);
var hex = '';
SHA256.hash = function (message) {
var digest = SHA256.digest(message);
var hex = '';
for (var i = 0; i < digest.length; i++) {
var s = '0' + digest[i].toString(16);
hex += s.length > 2 ? s.substring(1) : s;
hex += s.length > 2 ? s.substring(1) : s;
}
return hex;
return hex;
}
// == Convert to ES6 Module == //
export default SHA256;
export default SHA256;

View File

@ -1,74 +1,73 @@
'use strict'
const utils = {
int32ToBytes(word) {
var byteArray = []
for (var b = 0; b < 32; b += 8) {
byteArray.push((word >>> (24 - b % 32)) & 0xFF)
}
return byteArray
},
int32ToBytes(word) {
var byteArray = []
for (var b = 0; b < 32; b += 8) {
byteArray.push((word >>> (24 - b % 32)) & 0xFF)
}
return byteArray
},
stringtoUTF8Array(message) {
if (typeof message === 'string') {
var s = unescape(encodeURIComponent(message)) // UTF-8
message = new Uint8Array(s.length)
for (var i = 0; i < s.length; i++) {
message[i] = s.charCodeAt(i) & 0xff
}
}
return message
},
// ...buffers then buffers.foreach and append to buffer1
appendBuffer(buffer1, buffer2) {
buffer1 = new Uint8Array(buffer1)
buffer2 = new Uint8Array(buffer2)
let tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength)
tmp.set(buffer1, 0)
tmp.set(buffer2, buffer1.byteLength)
return tmp
},
stringtoUTF8Array(message) {
if (typeof message === 'string') {
var s = unescape(encodeURIComponent(message)) // UTF-8
message = new Uint8Array(s.length)
for (var i = 0; i < s.length; i++) {
message[i] = s.charCodeAt(i) & 0xff
}
}
return message
},
// ...buffers then buffers.foreach and append to buffer1
appendBuffer(buffer1, buffer2) {
buffer1 = new Uint8Array(buffer1)
buffer2 = new Uint8Array(buffer2)
let tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength)
tmp.set(buffer1, 0)
tmp.set(buffer2, buffer1.byteLength)
return tmp
},
int64ToBytes(int64) {
// we want to represent the input as a 8-bytes array
var byteArray = [0, 0, 0, 0, 0, 0, 0, 0]
int64ToBytes(int64) {
// we want to represent the input as a 8-bytes array
var byteArray = [0, 0, 0, 0, 0, 0, 0, 0]
for (var index = 0; index < byteArray.length; index++) {
var byte = int64 & 0xff
byteArray[byteArray.length - index - 1] = byte
int64 = (int64 - byte) / 256
}
for (var index = 0; index < byteArray.length; index++) {
var byte = int64 & 0xff
byteArray[byteArray.length - index - 1] = byte
int64 = (int64 - byte) / 256
}
return byteArray
},
return byteArray
},
hexToBytes(hexString) {
return new Uint8Array(hexString.match(/.{1,2}/g).map(byte => parseInt(byte, 16)))
},
hexToBytes(hexString) {
return new Uint8Array(hexString.match(/.{1,2}/g).map(byte => parseInt(byte, 16)))
},
stringToHex(bytes) {
return bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '')
},
stringToHex(bytes) {
return bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '')
},
equal(buf1, buf2) {
if (buf1.byteLength != buf2.byteLength) return false
var dv1 = new Uint8Array(buf1)
var dv2 = new Uint8Array(buf2)
for (var i = 0; i != buf1.byteLength; i++) {
if (dv1[i] != dv2[i]) return false
}
return true
},
equal(buf1, buf2) {
if (buf1.byteLength != buf2.byteLength) return false
var dv1 = new Uint8Array(buf1)
var dv2 = new Uint8Array(buf2)
for (var i = 0; i != buf1.byteLength; i++) {
if (dv1[i] != dv2[i]) return false
}
return true
},
bytesToHex(byteArray) {
var _byteArrayToHex = []
bytesToHex(byteArray) {
var _byteArrayToHex = []
for (var index = 0; index < byteArray.length; index++) {
_byteArrayToHex.push((byteArray[index] >>> 4).toString(16))
_byteArrayToHex.push((byteArray[index] & 15).toString(16));
}
for (var index = 0; index < byteArray.length; index++) {
_byteArrayToHex.push((byteArray[index] >>> 4).toString(16))
_byteArrayToHex.push((byteArray[index] & 15).toString(16));
}
return _byteArrayToHex.join("")
}
return _byteArrayToHex.join("")
}
}
export default utils

View File

@ -1,4 +1,4 @@
import {waitForConfig, watchConfig} from '../config.js'
import { waitForConfig, watchConfig } from '../config'
let config = {}

View File

@ -1,11 +1,11 @@
import {store} from '../api_deps.js'
import {stateAwait} from './utils/stateAwait.js'
import {Sha512} from 'asmcrypto.js'
import utils from '../api/deps/utils.js'
import {get, registerTranslateConfig} from '../../core/translate'
import { store } from '../api_deps'
import { stateAwait } from './utils/stateAwait'
import { Sha512 } from 'asmcrypto.js'
import utils from '../api/deps/utils'
import { get, registerTranslateConfig } from '../../core/translate'
registerTranslateConfig({
loader: lang => fetch(`/language/${lang}.json`).then(res => res.json())
loader: lang => fetch(`/language/${lang}.json`).then(res => res.json())
})
export const kdf = async (seed, salt, status = () => { }) => {

View File

@ -1,7 +1,7 @@
/**
* Not to be confused with register name...this is a special use case
*/
import {createTransaction, processTransaction, request} from './api.js'
import { createTransaction, processTransaction, request } from './api'
const TX_TYPE = 3 // NAME_REGISTRATION
const CHECK_LAST_REF_INTERVAL = 30 * 1000 // err 30 seconds

View File

@ -1,6 +1,6 @@
import {AES_CBC, HmacSha512} from 'asmcrypto.js'
import {kdf} from './kdf.js'
import Base58 from './deps/Base58.js'
import { AES_CBC, HmacSha512 } from 'asmcrypto.js'
import { kdf } from './kdf'
import Base58 from './deps/Base58'
const getRandomValues = window.crypto ? window.crypto.getRandomValues.bind(window.crypto) : window.msCrypto.getRandomValues.bind(window.msCrypto)

View File

@ -1,9 +1,9 @@
// Trade Bot
import TradeBotCreateRequest from './transactions/trade-portal/tradebot/TradeBotCreateRequest.js'
import TradeBotRespondRequest from './transactions/trade-portal/tradebot/TradeBotRespondRequest.js'
import signTradeBotTransaction from './transactions/trade-portal/tradebot/signTradeBotTransaction.js'
import DeleteTradeOffer from './transactions/trade-portal/tradeoffer/DeleteTradeOffer.js'
import {request} from './fetch-request'
import TradeBotCreateRequest from './transactions/trade-portal/tradebot/TradeBotCreateRequest'
import TradeBotRespondRequest from './transactions/trade-portal/tradebot/TradeBotRespondRequest'
import signTradeBotTransaction from './transactions/trade-portal/tradebot/signTradeBotTransaction'
import DeleteTradeOffer from './transactions/trade-portal/tradeoffer/DeleteTradeOffer'
import { request } from './fetch-request'
// TradeBotCreateRequest
export const tradeBotCreateRequest = (requestObject) => {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,7 @@
import TransactionBase from '../TransactionBase'
import publicKeyToAddress from '../../wallet/publicKeyToAddress'
import {Base58} from '../../deps/deps'
import {DYNAMIC_FEE_TIMESTAMP} from '../../constants'
import { Base58 } from '../../deps/deps'
import { DYNAMIC_FEE_TIMESTAMP } from '../../constants'
export default class RemoveRewardShareTransaction extends TransactionBase {
constructor() {

View File

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

View File

@ -1,11 +1,11 @@
export const randomBase58Generator = (digits) => {
digits = digits || 0
let base58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'.split('')
let result = ''
let char
while (result.length < digits) {
char = base58[Math.random() * 57 >> 0]
if (result.indexOf(char) === -1) result += char
}
return result
digits = digits || 0
let base58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'.split('')
let result = ''
let char
while (result.length < digits) {
char = base58[Math.random() * 57 >> 0]
if (result.indexOf(char) === -1) result += char
}
return result
}

View File

@ -1,31 +1,31 @@
import {store} from '../../api.js'
import { store } from '../../api'
let subscriptions = []
// Have to wait with init because something import stateAwait before the store gets initialized
let initialized = false
const init = () => {
initialized = true
store.subscribe(() => {
const state = store.getState()
initialized = true
store.subscribe(() => {
const state = store.getState()
subscriptions = subscriptions.filter(fn => fn(state))
})
subscriptions = subscriptions.filter(fn => fn(state))
})
}
export const stateAwait = fn => {
return new Promise((resolve, reject) => {
// Check immediately...then if not true store it
if (!initialized) {
init()
}
if (fn(store.getState())) resolve()
subscriptions.push(state => {
if (fn(state)) {
resolve()
return true
}
return false
})
})
return new Promise((resolve, reject) => {
// Check immediately...then if not true store it
if (!initialized) {
init()
}
if (fn(store.getState())) resolve()
subscriptions.push(state => {
if (fn(state)) {
resolve()
return true
}
return false
})
})
}

View File

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

View File

@ -1,10 +1,10 @@
import Base58 from '../deps/Base58.js'
import BROKEN_RIPEMD160 from '../deps/broken-ripemd160.js'
import RIPEMD160 from '../deps/ripemd160.js'
import utils from '../deps/utils.js'
import {ADDRESS_VERSION} from '../constants.js'
import {Buffer} from 'buffer'
import {Sha256} from 'asmcrypto.js'
import Base58 from '../deps/Base58'
import BROKEN_RIPEMD160 from '../deps/broken-ripemd160'
import RIPEMD160 from '../deps/ripemd160'
import utils from '../deps/utils'
import { ADDRESS_VERSION } from '../constants'
import { Buffer } from 'buffer'
import { Sha256 } from 'asmcrypto.js'
const repeatSHA256 = (passphrase, hashes) => {
let hash = passphrase

View File

@ -1,8 +1,8 @@
import Base58 from '../deps/Base58.js'
import Base58 from '../deps/Base58'
export const validateAddress = (address) => {
const decodePubKey = Base58.decode(address)
return decodePubKey instanceof Uint8Array && decodePubKey.length == 25;
return decodePubKey instanceof Uint8Array && decodePubKey.length == 25
}

View File

@ -1,4 +1,4 @@
import {store} from './api.js'
import { store } from './api'
let config = false
let loaded = false